Create new root user mysql
To create a new root user in MySQL, you can use the following steps:
Method 1: Using the mysql
command-line tool
-
Open a terminal or command prompt and navigate to the MySQL installation directory.
-
Run the following command to start the MySQL client:
mysql -u root -p
This will prompt you to enter the current root password. If you don't know the password, you can skip this step and use the
--skip-password
option instead. -
Once you're logged in, run the following command to create a new root user:
CREATE USER 'new_root'@'%' IDENTIFIED BY 'new_password';
Replace
new_root
with the desired username andnew_password
with the desired password. -
Grant the new user the
SUPER
privilege, which is required for the root user:GRANT SUPER ON *.* TO 'new_root'@'%';
-
Flush the privileges to apply the changes:
FLUSH PRIVILEGES;
Method 2: Using the
mysql_secure_installation
script -
Run the following command to start the
mysql_secure_installation
script:mysql_secure_installation
This script will prompt you to set a new root password, remove anonymous user accounts, and disable remote root login.
-
When prompted to set a new root password, enter the desired password.
-
When prompted to create a new root user, enter the desired username and password.
-
The script will automatically grant the new user the
SUPER
privilege and flush the privileges.
Method 3: Using the mysql
command-line tool with the --skip-password
option
- Run the following command to start the MySQL client with the
--skip-password
option:mysql --skip-password
This will allow you to create a new root user without entering the current root password.
- Run the following command to create a new root user:
CREATE USER 'new_root'@'%' IDENTIFIED BY 'new_password';
Replace
new_root
with the desired username andnew_password
with the desired password. - Grant the new user the
SUPER
privilege:GRANT SUPER ON *.* TO 'new_root'@'%';
- Flush the privileges:
FLUSH PRIVILEGES;
Note: Make sure to replace
new_root
andnew_password
with the desired values. Also, be careful when creating a new root user, as it can potentially compromise the security of your MySQL installation.