Home >Database >Mysql Tutorial >How to set root user password in MySQL?

How to set root user password in MySQL?

WBOY
WBOYOriginal
2024-03-14 18:09:04583browse

How to set root user password in MySQL?

MySQL is a popular open source relational database management system used to store and manage data. In MySQL, the root user is the user with the highest authority and is usually used to manage database instances. Setting the root user's password is one of the important steps to protect database security.

The following will demonstrate how to set the root user's password in MySQL, including specific code examples:

  1. First, please use the root user to log in to the MySQL database. Enter the following command in the terminal and press Enter:
mysql -u root -p
  1. Then the system will prompt you to enter the password of the root user. After entering, press Enter to continue.
  2. Next, use the following command to set a new password for the root user. Please replace new_password with the password you want to set, and then press Enter:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Note: Please be sure to replace new_password with the one you set Security Code.

  1. After the setting is completed, you can use the following command to exit the MySQL database:
exit;

Through the above steps, you have successfully set the root user password of the MySQL database. Remember to change your password regularly to increase database security. Have fun using MySQL!

The above is the detailed content of How to set root user password in MySQL?. 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