MySQL login password forget, in fact, the solution is very simple, just need to add a line "skip authorization Table" parameter selection in MySQL main configuration file my.cnf!
Add the following line in MY.CNF:
[Email protected] ~]# VIM/ETC/MY.CNF
........
Skip-grant-tables //Skip Authorization Form
Then restart the MySQL service, you can login without password
[Email protected] ~]#/etc/init.d/mysqld restart
Reset Password After login
[[email protected] ~]# MySQL
Mysql> select Host,user,password from Mysql.user;
+--------------------+------+-------------------------------------------+
| Host | user | password |
+--------------------+------+-------------------------------------------+
| localhost | Root | *481aca1bd6d1e86221244904e9c0faba33b40b84 |
| host-192-168-1-117 | Root | |
| 127.0.0.1 | Root | |
| :: 1 | Root | |
| localhost | | |
| host-192-168-1-117 | | |
+--------------------+------+-------------------------------------------+
6 rows in Set (0.00 sec)
mysql> Update mysql.user set Password=password ("123456") where host= "localhost" and user= "root";
Query OK, 1 row affected (0.02 sec)
Rows matched:1 changed:1 warnings:0
mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> select Host,user,password from Mysql.user;
+--------------------+------+-------------------------------------------+
| Host | user | password |
+--------------------+------+-------------------------------------------+
| localhost | Root | *6bb4837eb74329105ee4568dda7dc67ed2ca2ad9 |
| host-192-168-1-117 | Root | |
| 127.0.0.1 | Root | |
| :: 1 | Root | |
| localhost | | |
| host-192-168-1-117 | | |
+--------------------+------+-------------------------------------------+
6 rows in Set (0.00 sec)
Mysql>
Comment The line that you added in My.cnf again, and then restart MySQL
[Email protected] ~]# VIM/ETC/MY.CNF
........
#skip-grant-tables
[Email protected] ~]#/etc/init.d/mysqld restart
[Email protected] ~]# mysql-p123456
Mysql>
--------------------------------------------------------------------------------------------------------------- ---
MySQL login error is as follows:
[Email protected] ~]# mysql-p123456
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (111)
[[email protected] ~]# ps-ef|grep MySQL
Root 28279 1 0 12:55? 00:00:00/bin/sh/usr/local/mysql//bin/mysqld_safe--datadir=/data/mysql/data--pid-file=/data/mysql/data/ Mysql.pid
MySQL 29059 28279 0 12:55? 00:00:01/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql/--datadir=/data/mysql/data--plugin-dir=/usr/ Local/mysql//lib/plugin--user=mysql--log-error=/data/mysql/data/mysql-error.log--pid-file=/data/mysql/data/ Mysql.pid--socket=/usr/local/mysql/var/mysql.sock--port=3306
Root 30726 11268 0 12:58 pts/2 00:00:00 grep mysql
The current Mysql.sock file path is/usr/local/mysql/var/mysql.sock,
Workaround: Do a soft link
[Email protected] ~]# Ll/usr/local/mysql/var/mysql.sock
Rwxrwxrwx. 1 mysql mysql 0 Nov 12:55/usr/local/mysql/var/mysql.sock
[Email protected] ~]# rm-f/var/lib/mysql/mysql.sock
[Email protected] ~]# ln-s/usr/local/mysql/var/mysql.sock/var/lib/mysql/mysql.sock
That would be fine.
[Email protected] ~]# mysql-p123456
Mysql>
MySQL login password forgot the solution