How to solve the problem of forgetting the root password of MySQL

Source: Internet
Author: User
There are two prerequisites for changing the root password of MySQL if I forget the root password :? You have the permission to modify the MySQL configuration file. You have the permission to restart the MySQL service. modify the configuration file first :? Reference # vimetcmy. cnf? [Mysqld]? Datadirvarlibmysql? Socketvarlibmysqlmysql. sock? Usermysql? # D

There are two prerequisites for changing the root password of MySQL if I forget the root password :? You have the permission to modify the MySQL configuration file. You have the permission to restart the MySQL service. modify the configuration file first :? Reference # vim/etc/my. cnf? [Mysqld]? Datadir =/var/lib/mysql? Socket =/var/lib/mysql. sock? User = mysql? # D

How to solve the problem of forgetting the root password of MySQL

To change the root password of MySQL, there are two prerequisites :?

  • You have the permission to modify the MySQL configuration file.
  • You have the permission to restart the MySQL service.


First modify the configuration file :?

Reference
# Vim/etc/my. cnf?

[Mysqld]?
Datadir =/var/lib/mysql?
Socket =/var/lib/mysql. sock?
User = mysql?
# Default to using old password format for compatibility with mysql 3.x?
# Clients (those using the mysqlclient10 compatibility package ).?
Old_passwords = 1?

# Disabling symbolic-links is recommended to prevent assorted security risks ;?
# To do so, uncomment this line :?
# Symbolic-links = 0?

[Mysqld_safe]?
Log-error =/var/log/mysqld. log?
Pid-file =/var/run/mysqld. pid



In[Mysqld]AddSkip-grant-tables, That is, the permission verification is skipped .?

Then log on to MySQL and change the root password :?

Reference 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-?

Database changed?
Mysql> update user SET Password = password (' ') Where user = 'root ';?
Query OK, 3 rows affected (0.00 sec )?
Rows matched: 3? Changed: 3? Warnings: 0?

Mysql> flush privileges ;?
Query OK, 0 rows affected (0.00 sec )?

Mysql> quit?
Bye?



Then, change the modified configuration file back and restart the service :?

Reference
# Service mysqld restart?
Stop a MySQL instance :????????????????????????????????????? ????????? [OK]?
Start MySQL :????????????????????????????????????? ????????? [OK]?


It's so easy to forget the password of Mysql.
PS: more decisive method :?

Reference
Disable mysqld?
Run the command line mysqld -- skip-grant-tables & password-less login !?

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.