如果有一天你忘记了root的密码,我们可以利用 --skip-grant-tables这个参数,具体实施如下:
[root@HE1 bin]# mysql -uroot -p
Enter password:
ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: YES)
[root@HE1 bin]# ps-ef|grep mysql
root 7572 2398 0 00:58 pts/1 00:00:00 /bin/sh ./mysqld_safe--defaults-file=/etc/my.cnf
mysql 8199 7572 0 00:58 pts/1 00:00:00 /usr/local/mysql/bin/mysqld--defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql--plugin-dir=/usr/local/mysql/lib/plugin --user=mysql--log-error=/data/mysql/error.log --open-files-limit=3072--pid-file=/data/mysql/HE1.pid --socket=/data/mysql.sock --port=3306
root 8230 2398 0 00:59 pts/1 00:00:00 grep mysql
[root@HE1 bin]# kill -9 8199 7572
[root@HE1 bin]# ps-ef|grep mysql
root 8232 2398 0 00:59 pts/1 00:00:00 grep mysql
[1]+ Killed ./mysqld_safe--defaults-file=/etc/my.cnf
[root@HE1 bin]# ps-ef|grep mysql
root 8234 2398 0 00:59 pts/1 00:00:00 grep mysql
[root@HE1 bin]# ./mysqld_safe --defaults-file=/etc/my.cnf--skip-grant-tables &
[1] 8235
[root@HE1 bin]#160317 00:59:43 mysqld_safe Logging to ‘/data/mysql/error.log‘.
160317 00:59:43mysqld_safe Starting mysqld daemon with databases from /data/mysql
[root@HE1 bin]# mysql -uroot
Welcome to the MySQLmonitor. Commands end with ; or \g.
Your MySQLconnection id is 1
Server version:5.6.16-log MySQL Community Server (GPL)
Copyright (c) 2000,2014, Oracle and/or its affiliates. All rights reserved.
Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates. Othernames may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘for help. Type ‘\c‘ to clear the current input statement.
mysql> quit
Bye
[root@HE1 bin]# mysql
Welcome to the MySQLmonitor. Commands end with ; or \g.
Your MySQLconnection id is 2
Server version:5.6.16-log MySQL Community Server (GPL)
Copyright (c) 2000,2014, Oracle and/or its affiliates. All rights reserved.
Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates. Othernames may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘for help. Type ‘\c‘ to clear the current input statement.
mysql> quit
Bye
本文中采用kill-9的方式,这种方式不建议在生产库中使用,生产库中应采用正常停库
本文出自 “岁伏” 博客,请务必保留此出处http://suifu.blog.51cto.com/9167728/1753985
原文地址:http://suifu.blog.51cto.com/9167728/1753985