Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the mysqladmin command to change the MySQL password and forget the password

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Change the password:

1. For example, if your root user does not have a password and you want to change the password to 123456, the command is:

Mysqladmin-u root password 123456

two。 If your root now has a password (123456), the command to change the password to abcdef is:

Mysqladmin-u root-p password abcdef

Note that you will be asked the old password after entering the command enter. After entering the old password 123456, the command will be completed and the password will be changed successfully.

3. If your root now has a password (123456), the command to change the password to abcdef is:

Mysqladmin-u root-p123456 password abcdef (Note-p do not separate from the following password

Start to write, write together, or you will make mistakes, as shown below)

4. Using phpmyadmin, which is the easiest, modify the user table of the mysql library

But don't forget to use the PASSWORD function.

Forget your password:

Below we provide 6 different ways to change the password of mysql root users and to add mysql users.

Method one

Using phpmyadmin, which is the easiest, modify the user table of the mysql library

But don't forget to use the PASSWORD function.

Method two

Using mysqladmin, this is a special case of the previous declaration.

Mysqladmin-u root-p password mypasswd

After entering this command, you need to enter the original password of root, and then the password of root will be changed to mypasswd.

Change the root in the command to your user name, and you can change your own password.

Of course, if your mysqladmin can't connect to mysql server, or if you can't execute mysqladmin,

Then this method is ineffective.

And mysqladmin can't clear the password.

The following methods are used at the mysql prompt and must have root permission for mysql:

Method three

Mysql > INSERT INTO mysql.user (Host,User,Password)

VALUES ('%', 'jeffrey',PASSWORD (' biscuit'))

Mysql > FLUSH PRIVILEGES

To be exact, this is adding a user with the user name jeffrey and the password biscuit.

There is this example in the mysql Chinese reference Manual, so I wrote it out.

Note that you use the PASSWORD function, and then you use FLUSH PRIVILEGES.

Method 4

Same as method 3, except that the REPLACE statement is used

Mysql > REPLACE INTO mysql.user (Host,User,Password)

VALUES ('%', 'jeffrey',PASSWORD (' biscuit'))

Mysql > FLUSH PRIVILEGES

Method five

Use the SET PASSWORD statement

Mysql > SET PASSWORD FOR jeffrey@ "%" = PASSWORD ('biscuit')

The PASSWORD () function must also be used.

But you don't need to use FLUSH PRIVILEGES.

Method 6

Use GRANT... IDENTIFIED BY statement

Mysql > GRANT USAGE ON *. * TO jeffrey@ "%" IDENTIFIED BY 'biscuit'

The PASSWORD () function is unnecessary here, and you don't need to use FLUSH PRIVILEGES.

Note: PASSWORD () [not] performs password encryption in the same way that Unix passwords are encrypted.

The solution of MySQL forgetting password

If MySQL is running, kill it first: killall-TERM mysqld.

Start MySQL: bin/safe_mysqld-- skip-grant-tables &

You can enter MySQL without a password.

And then there is.

> use mysql

> update user set password=password ("new_pass") where user= "root"

> flush privileges

Kill MySQL again and start MySQL in the normal way.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report