码迷,mamicode.com
首页 > 数据库 > 详细

MySQL5.7修改默认密码、随机密码

时间:2017-09-17 01:27:02      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:root用户   now()   my.cnf   命令   mda   启动   red   lin   用户密码   

mysql5.7以后默认生成随机密码,修改root用户密码

  1、修改配置参数
Linux:     /etc/my.cnf
Windows:    C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
[mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动时不对密码进行验证
或者启动服务时添加命令: service mysqld start --skip-grant-tables

  2、重启 mysql 服务
Linux:      service mysqld restart
Windows:     net start/stop MySQL57

  3、使用 root 用户登录到 mysql:
Linux:      mysql -u root
Windows:  必须用管理员权限启动cmd,切换到C:\Program Files\MySQL\MySQL Server 5.7\bin,mysql -u root -p

  4、切换到mysql数据库,更新 user 表,user表里面保存了全部用户信息
update user set password=password(‘root‘) where user="new_password";
alter user ‘root‘@‘localhost‘ identified by ‘new_password‘;
update user set authentication_string = password(‘new_password‘), password_expired = ‘n‘, password_last_changed = now() where user = ‘root‘;

  注:在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string

  5、退出 mysql,编辑 /etc/my.cnf 或 C:\ProgramData\MySQL\MySQL Server 5.7\my.ini文件,删除 skip-grant-tables=1 行
MySQL三个退出命令:    exit;    quit;    \q;

  6、重启 mysqld 服务,再用新密码登录即可

注:mysql 5.7 在初始安装后(centos7 操作系统)会生成随机初始密码,并在 /var/log/mysqld.log 中有记录,可以通过 cat 命令查看,找 password 关键字找到密码

 

MySQL5.7修改默认密码、随机密码

标签:root用户   now()   my.cnf   命令   mda   启动   red   lin   用户密码   

原文地址:http://www.cnblogs.com/zengming/p/7533609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!