MySQL is currently the most popular open source relational database management system, which greatly improves the efficiency of data storage and retrieval. For MySQL administrators, it is very important to ensure the security of MySQL, and setting the root user password is also an important step.
The root user does not have a password after MySQL is installed by default. This means that anyone who knows the IP address and port number of the MySQL service can use the root user to operate. To make MySQL more secure, we need to set a password for the root user.
The following are the steps to set the MySQL root password:
The MySQL server can be local or remote. If the MySQL server is local, log in using the following command:
mysql -u root
This will use the root user to connect to the MySQL server. If the MySQL server is remote, add the IP address or domain name to the above command.
After changing the user password on the MySQL server, you must refresh the MySQL permissions for the changes to take effect. Use the following command to refresh MySQL permissions:
FLUSH PRIVILEGES;
The following command on the command line will change the MySQL root user password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my-new-password';
Note, replace "my-new-password" with your actual password. This command will update MySQL's users table to encrypt the root user's password with the given password.
Use the following command to exit the MySQL server:
exit
After setting the root user password, other users or applications can connect to the MySQL server , the root user password is required for authentication. This ensures the security of the MySQL server.
Of course, setting the root user password is not the only measure to manage MySQL security. Other security measures include restricting remote access, prohibiting root users from accessing MySQL from remote hosts, and more.
Summary
Setting the root user password on the MySQL server is one of the basic measures to ensure server security. Administrators are strongly recommended to do this before using MySQL. If necessary, other security measures should also be considered, such as restricting remote access, etc.
The above is the detailed content of mysql root set password. For more information, please follow other related articles on the PHP Chinese website!