linux下mysql5.7初始密码查看及忘记密码重置 | 您所在的位置:网站首页 › linux系统第一次开机有密码吗 › linux下mysql5.7初始密码查看及忘记密码重置 |
前段时间安装mysql5.7后,第一次登陆发现空密码怎么都登陆不成功,后来网上查了一下发现,从5.7开始会自动生成一个随机密码了。 查看初始密码 grep 'temporary password' /var/log/mysqld.log 2016-07-08T02:25:46.311098Z 1 [Note] A temporary password is generated for root@localhost: MtPqF0/oN5zo 其中“MtPqF0/oN5zo”就为我们要找的初始密码另外一种方法查看默认密码: cat /root/.mysql_secret The random password set for the root userat Fri Jan 10 20:00:34 2014 (local time): aJqZsA2m “aJqZsA2m”就是我们要找的初始密码ps:这上面两种方法都是在网上找的,第一个方法我是在log中没有找到对应的密码记录,第二方法找到的密码也登陆不进去,不知道哪里操作错误了,最后还是使用的下面的mysql找回密码大招登陆进去的 mysql密码找回 方法一: vi /etc/my.cnf在[mysqld]下加上 skip-grant-tables,如: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tables重启mysql service mysqld restart登陆mysql后就可以修改密码了 mysql -u root update mysql.user set authentication_string=PASSWORD('123456') where User='root'; flush privileges;然后改回my.cnf重启mysql。 方法2: 先暂停mysql 以不检查权限的方式启动 bin/mysqld_safe --skip-grant-tables &登陆mysql后就可以修改密码了 mysql -u root update mysql.user set authentication_string=PASSWORD('123456') where User='root'; flush privileges;然后重启mysql就ok了 service mysqld restart登录后任何操作都会有这个提示: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1还需要刷新一次密码才行 set password for root@localhost = password('123456'); flush privileges; |
CopyRight 2018-2019 实验室设备网 版权所有 |