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

How to change the password of root account by MySQL

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how MySQL changes the password of root account. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

How to change the password of a root user in the MySQL database? Here are some ways to change the password of a root user

1: modify using the set password statement

Mysql > select user ()

+-+

| | user () |

+-+

| | root@localhost |

+-+

1 row in set (0.08 sec)

Mysql > set password=password ('123456')

Query OK, 0 rows affected (0.00 sec)

Mysql > flush privileges

Query OK, 0 rows affected (0.00 sec)

Mysql > exit

2: update the user table of mysql database

Mysql > use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with-A

Database changed

Mysql > update user set password=PASSWORD ('QwE123') where user='root'

Query OK, 4 rows affected (0.03 sec)

Rows matched: 4 Changed: 4 Warnings: 0

Mysql > flush privileges

Query OK, 0 rows affected (0.00 sec)

Mysql > quit

3: use the mysqladmin command to modify

The command is typically mysqladmin-u root-pairoldpassword' password newpass, as shown below:

[root@DB-Server] # mysqladmin-u root-pendant 123456' password 'Qwe123'

Warning: Using a password on the command line interface can be insecure.

Verify that the root password modification is successful

[root@DB-Server] # mysqladmin-u root-pendant 123456' password 'Qwe123'

Warning: Using a password on the command line interface can be insecure.

The above is to change the root password in the case of knowing the root password, if you forget the root password, how to change the root password?

1: stop the MySQL service first

[root@DB-Server ~] # service mysql stop

Shutting down MySQL.. [OK]

[root@DB-Server ~] #

Or

[root@DB-Server ~] # / etc/rc.d/init.d/mysql stop

Shutting down MySQL.. [OK]

2: then use the mysqld_safe command to start mysql and update the password of the root account

-- skip-grant-tables: do not start grant-tables (authorization table) and skip permission control.

-- skip-networking: skip the TCP/IP protocol and access only locally (this option is not required. You don't have to) Yes, you don't.

[root@DB-Server] # mysqld_safe-- user=mysql-- skip-grant-tables-- skip-networking &

[1] 5145

You have new mail in / var/spool/mail/root

[root@DB-Server ~] # 150709 14:10:53 mysqld_safe Logging to'/ var/lib/mysql/DB-Server.localdomain.err'.

150709 14:10:53 mysqld_safe Starting mysqld daemon with databases from / var/lib/mysql

[root@DB-Server ~] # mysql-u root mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with-A

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 1

Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server-Advanced Edition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

| | test |

+-+

4 rows in set (0.00 sec)

Mysql > use mysql

Database changed

Mysql > UPDATE user SET password=PASSWORD ("Qwe123") WHERE user='root'

Query OK, 4 rows affected (0.01sec)

Rows matched: 4 Changed: 4 Warnings: 0

Mysql > flush privileges

Query OK, 0 rows affected (0.00 sec)

Mysql > exit

Bye

3: restart the MySQL service.

Thank you for reading! This is the end of the article on "how MySQL changes the password of root account". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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: 257

*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