Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of mysql changing password through cmd

Shulou Source: shulou.com Published: 2022-06-01 04:12:25 09月15日 Update

This article will explain in detail how mysql changes passwords through cmd. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Methods: 1, use "SET PASSWORD FOR 'root'@'localhost'=PASSWORD (' newpass');" command; 2, use "mysqladmin-u root password oldpass" newpass ".

Mysql's method of changing the password through cmd:

Initialize and set the 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 methods

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. When the root password is lost, set 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 configuration file of mysql (default is / etc/my.cnf), and add a line skip-grant-tables under [mysqld].

2. Restart the mysql service service mysqld restart after saving the configuration file

3. Log in to mysql with mysql-u root-p, enter directly without entering the password, and then change the password according to the above process.

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

So much for sharing about mysql's method of changing passwords through cmd. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Password method file configuration command more process article service good practical one line content article knowledge face reference help related login Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft MySQL Huawei Docker