1
| [iyunv@gz1 ~]# mysqladmin -uroot password '123456' 给MySQL设置一个密码
|
1
| [iyunv@gz1 ~]# mysql -uroot -p123456 本地登录MySQL
|
假如我们现在MySQL密码已忘记,现在进行重置。
1
| [iyunv@gz1 ~]# vim /etc/my.cnf 编辑配置文件
|
1
| skip-grant 加入这个保存退出(不授权直接可以登录)
|
1
2
3
| [iyunv@gz1 ~]# /etc/init.d/mysqld restart 重启一下MySQL
Shutting down MySQL..... SUCCESS!
Starting MySQL. SUCCESS!
|
1
2
3
| [iyunv@gz2 ~]# mysql -uroot 直接就可以登录了
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
|
1
2
3
| mysql> use mysql //使用mysql库
mysql> update user set password=password('654321') where user='root'; //更新表(修改密码)
mysql>quit
|
然后找到/etc/my.cnf配置文件,删除之前的skip-grant命令,保存退出后重启MySQL服务
[iyunv@gz1 ~]# /etc/init.d/mysqld restart1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@gz2 ~]# mysql -uroot -p654321 更改密码生效,重新登入
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 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.
|
|