Home >Database >Mysql Tutorial >How to add password for root user in MySQL database?
Title: Specific method to add password for root user in MySQL database
MySQL database is the most popular open source relational database management system in the world and is widely used in various fields. in various websites and applications. In the MySQL database, the root user is the super user with the highest authority and has full control over the database. In order to enhance the security of the database, it is usually recommended to set a password for the root user to prevent unauthorized access and operations.
To add a password for the root user in the MySQL database, you can follow the following specific steps:
First, you need to be the root user Log in to the MySQL database with your identity. Open the command line or MySQL Workbench and use the following command to connect to the database:
mysql -u root -p
The system will prompt you to enter the password of the MySQL root user. After entering the correct password, you can log in to the database.
After successfully logging in to the database, use the following command to add a password for the root user:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
Among them, new_password
is the new password you want to set for the root user. After executing this command, the password of the root user will be changed to the new password.
After modifying the root user password, you need to refresh the permissions for the modification to take effect. Execute the following command to refresh the permissions:
FLUSH PRIVILEGES;
In this way, you have successfully added a password for the root user in the MySQL database. From now on, you can only log in and manage the database as the root user by entering the correct password.
To sum up, adding a password for the root user in the MySQL database is a very important security measure that can effectively protect the security of the database. Through the above specific steps, you can easily set a password for the root user and improve the security of the database. I hope this article can help you better understand and operate the root user password settings in the MySQL database.
The above is the detailed content of How to add password for root user in MySQL database?. For more information, please follow other related articles on the PHP Chinese website!