Home  >  Article  >  Database  >  mysql root set password

mysql root set password

WBOY
WBOYOriginal
2023-05-14 09:24:07910browse

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:

  1. Log in to the MySQL server

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.

  1. Refresh MySQL Permissions

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;
  1. Change MySQL root password

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.

  1. Exit the MySQL server

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:mysql set caseNext article:mysql set case