Home  >  Article  >  Database  >  Some methods for changing root password in MySQL

Some methods for changing root password in MySQL

小云云
小云云Original
2018-03-30 14:42:051835browse

This article mainly shares with you some methods of changing the root password of MySQL, hoping to help everyone.

Method 1: Use the SET PASSWORD command

mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

mysql> quit; //Exit the mysql console

After setting the password, test login:

mysql -u root -p"newpass" //-p and password There must be no spaces between them

Or enter mysql -u root -p and press Enter to let the system prompt you to enter the password

Method 2: Use mysqladmin

mysqladmin -u root password "newpass"

If root has already set a password, use the following method

mysqladmin -u root password oldpass "newpass"

Method 3: Use UPDATE directly Edit user table

mysql -u root

mysql> use mysql;

mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

mysql> FLUSH PRIVILEGES;

When you lose the root password, you can do this

mysqld_safe --skip-grant-tables&

mysql -u root mysql

mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

mysql> FLUSH PRIVILEGES;

Related recommendations:

Introduction to the methods of changing the root password and installation and configuration tuning in Mysql

Summary of using the cmd command to change the root password in MYSQL

How to change the root password sharing in Mysql5.7

The above is the detailed content of Some methods for changing root 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