Home  >  Article  >  Database  >  How to change mysql password through cmd?

How to change mysql password through cmd?

青灯夜游
青灯夜游Original
2020-09-02 11:45:566003browse

Method: 1. Use the "SET PASSWORD FOR 'root'@'localhost'=PASSWORD('newpass');" command; 2. Use "mysqladmin -u root password oldpass "newpass"".

How to change mysql password through cmd?

Mysql method to change password through cmd:

1. Initialization setting password

/etc/init.d/mysql stop 
cd /usr/local/mysql 
mysqld_safe –user=mysql –skip-grant-tables –skip-networking & 
mysql -u root mysql 
mysql > UPPATE user SET password=PASSWORD(‘newpassword’) where USER=’root’; 
mysql > FLUSH PRIVILEGES; 
mysql > quit ; 
/etc/init.d/mysql restart 
mysql -u root -p

Method 1: Use the SET PASSWORD command

mysql -u root 
  mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘newpass’);

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: Edit the user table directly with UPDATE

mysql -u root 
  mysql> use mysql; 
  mysql> UPDATE user SET Password = PASSWORD(‘newpass’) WHERE user = ‘root’; 
  mysql> FLUSH PRIVILEGES;

2. Set the root password when you lose the root password

Method 1:

mysqld_safe –skip-grant-tables& 
  mysql -u root mysql 
  mysql> UPDATE user SET password=PASSWORD(“new password”) WHERE user=’root’; 
  mysql> FLUSH PRIVILEGES;

Method 2:
1. Modify the mysql configuration file (default is /etc/my.cnf) and add a line skip-grant-tables under [mysqld]

2. After saving the configuration file, restart mysql service service mysqld restart

3. Mysql -u root -p log in to mysql, then press Enter without entering the password, and then change the password according to the above process

4. After the password has been changed, follow In process 1, delete the line in the configuration file and then restart the mysql service

Related recommendations: "mysql tutorial"

The above is the detailed content of How to change mysql password through cmd?. 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