Home > Database > Mysql Tutorial > How to set password for root in mysql

How to set password for root in mysql

WBOY
Release: 2023-05-29 13:22:24
forward
2288 people have browsed it

Step 1: First log in to MySQL

Enter the following command in the terminal to enter the MySQL console:

sudo mysql

If you enter this You will be prompted for a password after the command. Please enter the password of your root user.

Step 2: Change the password

After we enter the MySQL console, we can start to change the password of the root user. Follow the command below to set the password:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

'new_password' is the new password you want to set.

Step 3: Refresh permissions

After running the above command, you need to refresh the permissions so that MySQL can use the new password to authenticate the root account. Enter the following command in the MySQL console:

FLUSH PRIVILEGES;

Step 4: Exit MySQL

After completing the password change, you can exit MySQL through the following command:

exit

Now you have successfully changed the password of the root account.

How to set a secure MySQL root password

For a network-based service, password security is very important. If a hacker cracks the root account, they can easily access the database, which will have serious consequences for the user and the company. Therefore, when setting the MySQL root password, you must abide by the following rules:

  1. The password must be no less than 10 characters long

  2. The password consists of letters , numbers and symbols

  3. Avoid using easy-to-guess passwords, such as birthday, 123456, etc.

  4. Avoid using public information, such as company name or Your name

  5. Change your password regularly

If you are not sure how to set a strong password, you can use some password generator tools, such as 1Password or LastPass.

The above is the detailed content of How to set password for root in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template