In Linux, MySQL5.6.15-forget the root password-Reset

Source: Internet
Author: User

Mysql5.6.15 forget the root password of the database:

[Root @ oraserver139 ~] # Mysql-uroot-p
Enter password:
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)

View the currently installed mysql version:
Root @ oraserver139 ~] # Rpm-qa | grep MySQL
MySQL-server-5.6.15-1.el6.x86_64
MySQL-client-5.6.15-1.el6.x86_64
MySQL-shared-compat-5.6.15-1.el6.x86_64
MySQL-devel-5.6.15-1.el6.x86_64
Perl-DBD-MySQL-4.022-1.el6.rfx.x86_64


Stop mysql service:
[Root @ oraserver139 ~] # Service mysql stop
Shutting down MySQL... SUCCESS!

Go to the skip-grant-tables mode:

[Root @ oraserver139 ~] # Mysqld_safe -- skip-grant-tables
140211 15:37:49 mysqld_safe Logging to '/var/lib/mysql/oraserver139.err '.
140211 15:37:49 mysqld_safe Starting mysqld daemon with databases from/var/lib/mysql


Now you can access mysql without a password:

[Root @ oraserver139 ~] # Mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 1
Server version: 5.6.15 MySQL Community Server (GPL)

Copyright (c) 2000,201 3, 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.

Go to the mysql System 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-
Database changed

Modify the root account password:
Mysql> update user set password = password ("12345") where user = "root ";
Query OK, 4 rows affected (0.02 sec)
Rows matched: 4 Changed: 4 Warnings: 0


Refresh permission:
Mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Mysql> exit
Bye


Stop the mysql process:

[1] + Stopped mysqld_safe -- skip-grant-tables

Start mysql:

[Root @ oraserver139 ~] # Service mysql start
Starting MySQL SUCCESS!


Use the password you just modified to access mysql:

[Root @ oraserver139 ~] # Mysql-uroot-p12345
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3
Server version: 5.6.15

Copyright (c) 2000,201 3, 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;
ERROR 1820 (HY000): You must set password before executing this statement

Mysql> set password = PASSWORD ('20140901 ');
Query OK, 0 rows affected (0.00 sec)

Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Performance_schema |
| Test |
+ -------------------- +
4 rows in set (0.00 sec)

Modification completed;

Related Article

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.