Home >Database >Mysql Tutorial >How to set root password in mysql
MySQL is a commonly used open source database management system. Many websites and applications need to use MySQL for data storage and management. After installing MySQL, in order to ensure the security of the database, we need to set a root password.
The following are the steps to set the MySQL root password:
Use the following command to log in to MySQL:
sudo mysql
On the Ubuntu system, sudo permissions are required.
Use the following command to select the MySQL database:
use mysql;
Use the following command to view the current MySQL user:
select User from user;
Use the following command to view the current MySQL password:
select Host, User, Password from user;
Use the following command to modify the password of the root user:
update user set authentication_string=password('你的新密码') where user='root';
Among them, replace "your new password" with the password you want to set.
Refresh the MySQL database using the following command:
flush privileges;
Exit MySQL using the following command:
quit;
Setting the MySQL root password is completed.
Through the above steps, we can successfully set the MySQL root password to ensure the security of the database. In actual use, we can also configure and optimize MySQL in more detail to meet the needs of various scenarios.
The above is the detailed content of How to set root password in mysql. For more information, please follow other related articles on the PHP Chinese website!