微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐