MySQL forgets the root password. solution:

Source: Internet
Author: User
Today, I encountered a bad problem: I forgot my password when I used MySQL for a long time to create a database. This problem is also very common! To modify the MySQL root Password, you have two prerequisites: You have the permission to modify the MySQL configuration file, and you have the permission to restart the MySQL service. modify the configuration file first: Reference # vimetcmy. cnf [mysqld] datadirvarli

Today, I encountered a bad problem: I forgot my password when I used MySQL for a long time to create a database. This problem is also very common! To modify the MySQL root Password, you have two prerequisites: You have the permission to modify the MySQL configuration file, and you have the permission to restart the MySQL service. First, modify the configuration file: Reference # vim/etc/my. cnf [mysqld] datadir =/var/li

Today, I encountered a bad problem: I forgot my password when I used MySQL for a long time to create a database. This problem is also very common!
There are two prerequisites for modifying the MySQL root Password:
  • 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]Add Skip-grant-tablesTo skip permission verification.

Then log on to MySQL and change the root password:
Reference
# Mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3
Server version: 5.0.95 Source distribution

Copyright (c) 2000,201 1, 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> 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, modify the configuration file and restart the service:
Reference
# Service mysqld restart
Stop MySQL: [OK]
Start MySQL: [OK]


Success!

PS: more decisive method:
Reference
Disable mysqld
Execute mysqld -- skip-grant-tables & password-free logon on the command line!

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.