mysql5.7未生成初始密码.mysql_secert文件,登陆数据库
今天在CentOS 6.5上安装mysql5.7时遇到一个问题,没有初始化密码。在mysql5.7之前的版本首次登陆是无需密码的,但是5.7起会生成一个初始化密码/root/.mysql_secert
cat /root/.mysql_secert 就可以查看初始化密码了
但是我的安装没有发现.mysql_secert文件。
这种情况的解决方案:
mysqld_safe --user=mysql --skip-grant-tables & #跳过授权验证方式启动mysql mysql -uroot -p >use mysql; >desc user; #发现没有了password这个密码参数...略| authentication_string | text | YES | | NULL | || password_expired | enum('N','Y') | NO | | N | || password_last_changed | timestamp | YES | | NULL | || password_lifetime | smallint(5) unsigned | YES | | NULL | || account_locked | enum('N','Y') | NO | | N | |+------------------------+-----------------------------------+------+-----+-----------------------+-------+ >select user,host,authentication_string,password_expired from user;+-----------+-----------+-------------------------------------------+------------------+| user | host | authentication_string | password_expired |+-----------+-----------+-------------------------------------------+------------------+| root | localhost | *9AA01F6E2A80A823ACB72CC07337E2911404B5B8 | Y || mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N |+-----------+-----------+-------------------------------------------+------------------+#到这里不难发现root账户的密码已过期,还比5.6多出了一个mysql.sys用户 >update user set authentication_string=password('123456') where user='root';#修改密码为123456 >flush privileges; 重新登录mysql,首先停掉所有mysql进程
mysqld_safe --user=mysql & mysql -uroot -p >show databases;ERROR 1820 (HY000): You must reset your password using>#报错,需要使用alter user 修改密码,所以登陆进来的第一件事情是修改mysql的初始密码。否则使用会报错 >>'localhost' identified by 'aolens123..'; #这下就好了
可以看到5.7的密码字段改成了authentication_string,
页:
[1]