1、在命令行输入命令
root@centos64 mysql]# /usr/bin/mysqld_safe --skip-grant-tables&
2. 再启一个终端执行下面的一系列命令:
[root@centos64 proc]# mysql
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 1
server version: 5.6.13 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> update user set password=password('admin') where user='root';
error 1046 (3d000): no database selected
mysql> show databases ;
+--------------------+
| database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.06 sec)
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
mysql> update user set password=password('admin') where user='root';
query ok, 4 rows affected (0.04 sec)
rows matched: 4 changed: 4 warnings: 0
mysql> flush privileges; 也可以不用。
mysql> exit
bye
注意,就是有可能,user表中根本就没有root这个用户。
如果没有此用户,用:
mysql> insert into mysql.user(host,user,password,ssl_cipher,x509_issuer,x509_subject) values("localhost","root",password("admin"),"","","");
query ok, 1 row affected (0.10 sec)
3.授权。 给所有的权限
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'admin' ;
query ok, 0 rows affected (0.06 sec)
mysql> flush privileges;
再以正常的方式启动即可。
以上就是mysql之——忘记root密码如何操作的内容。