mysql学习之-密码管理默认密码,修改密码,解决忘记密码

1. mysql安装后认没有密码,初始化安装后认密码登录,需要马上修改root密码。
[root@MysqL ~]# cat /root/.MysqL_secret    --查看root账号密码
# The random password set for the root user at Tue Dec 13 18:59:06 2016 (local time): 7MhtyX3aZEl9OUf8
[root@MysqL ~]# MysqL -uroot -p    -- 登录MysqL
Enter password:               --(此处复制粘贴 7MhtyX3aZEl9OUf8)
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 2
Server version: 5.6.25
copyright (c) 2000, 2015, 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>   表示一切顺利成功。

2.  修改密码
MysqL> SET PASSWORD = PASSWORD('123456');   --设置密码为123456
[root@MysqL etc]# MysqL -uroot -p123456     --修改密码后,登录
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 39
Server version: 5.6.25 MysqL Community Server (GPL)
MysqL>     --登录成功

3. 忘记MysqL数据库root的密码后,如何修改密码
[root@MysqL etc]# service MysqL stop   --停止MysqL进程
Shutting down MysqL.... SUCCESS! 
[root@MysqL etc]# MysqLd_safe --skip-grant-tables&  --启动MysqL时不启动grant-tables,授权表。执行后出现下面画面,另起一个新会话。
[1] 3574
[root@MysqL etc]# 161215 06:13:53 MysqLd_safe Logging to '/var/lib/MysqL/MysqL.err'.
161215 06:13:53 MysqLd_safe Starting MysqLd daemon with databases from /var/lib/MysqL
[root@MysqL ~]# ps -ef|grep MysqL   --查看MysqL进程是否起来
root       3467   3440  0 05:29 pts/2    00:00:00 MysqL -uandy -px xx
root       3574   2845  0 06:13 pts/0    00:00:00 /bin/sh /usr/bin/MysqLd_safe --skip-grant-tables
MysqL      3677   3574  2 06:13 pts/0    00:00:00 /usr/sbin/MysqLd --basedir=/usr --datadir=/var/lib/MysqL --plugin-
MysqL> UPDATE user SET password=PASSWORD('cccccc') WHERE user='root';   --更改root密码
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4  Changed: 4  Warnings: 0
MysqL> FLUSH PRIVILEGES;    --权限更新
Query OK, 0 rows affected (0.00 sec)
[root@MysqL ~]# MysqL -uroot -p123456    --使用旧密码登录,发现不行,说明密码已经更新
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@MysqL ~]# MysqL -uroot -pcccccc   --新密码登录成功
Warning: Using a password on the command line interface can be insecure.
Welcome to the MysqL monitor.  Commands end with ; or \g.
MysqL>


相关文章

MySQL 死锁 是指两个或多个事务互相等待对方持有的锁,从而导...
在MySQL中,InnoDB引擎通过Next-Key Locking技术来解决幻读问...
在数据库事务管理中,Undo Log 和 Redo Log 是两种关键日志,...
case when概述 sql语句中的case语句与高级语言中的switch语句...
其实很简单,只是为了忘记,做个记录,用的时候方便。 不管是...
1.进入服务,找到mysql服务,在属性里找到mysql的安装路径 2...