Mysql5.6忘记root密码修改root密码的方法
mysql5.6忘记数据库的root密码:
[root@oraserver139 ~]# mysql -uroot -p
enter password:
error 1045 (28000): access denied for user 'root'@'localhost' (using password: no)
查看当前安装的mysql版本:
~]# 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
停止mysql服务:
[root@oraserver139 ~]# service mysql stop
shutting down mysql.. success!
进入到skip-grant-tables模式:
[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
现在就不需要密码就可以进入mysql了:
[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, 2013, 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系统数据库:
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 -a
database changed
修改root账户密码:
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
刷新权限:
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
mysql> exit
bye
停止mysql进程:
[1]+ stopped mysqld_safe --skip-grant-tables
启动mysql:
[root@oraserver139 ~]# service mysql start
starting mysql success!
使用刚才修改的密码进入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, 2013, 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('12345');
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)
修改完成;
以上所述是小编给大家介绍的mysql5.6忘记root密码修改root密码的方法,希望对大家有所帮助