您的位置:首页 > 数据库 > MySQL

MySQL忘记密码怎么办

2016-08-19 17:13 197 查看
如果有一天你忘记了root的密码,我们可以利用 --skip-grant-tables这个参数,具体实施如下:
[root@HE1 bin]# mysql -uroot -pEnter password:ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: YES)[root@HE1 bin]# ps-ef|grep mysqlroot      7572 2398  0 00:58 pts/1    00:00:00 /bin/sh ./mysqld_safe--defaults-file=/etc/my.cnfmysql     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=3306root      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 mysqlroot      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 mysqlroot      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 -urootWelcome to the MySQLmonitor.  Commands end with ; or \g.Your MySQLconnection id is 1Server 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 itsaffiliates. Othernames may be trademarks of their respectiveowners. Type 'help;' or '\h'for help. Type '\c' to clear the current input statement. mysql> quitBye[root@HE1 bin]# mysqlWelcome to the MySQLmonitor.  Commands end with ; or \g.Your MySQLconnection id is 2Server 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 itsaffiliates. Othernames may be trademarks of their respectiveowners. Type 'help;' or '\h'for help. Type '\c' to clear the current input statement. mysql> quitBye 

本文中采用kill-9的方式,这种方式不建议在生产库中使用,生产库中应采用正常停库
本文出自 “岁伏” 博客,请务必保留此出处http://suifu.blog.51cto.com/9167728/1753985
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: