linux安装了mysql之后初始化密码获取:出现了下面的内容,密码很尴尬,无法用root登录:
1 grep 'temporary password' /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: 4)ZqW0IooQ(a
出错如下:
[root@iZuf655czz7lmtn8v15tsjZ mysql]# mysql -uroot -p 4)ZqW0IooQ(a -bash: syntax error near unexpected token `)'
百度一番找到直接修改登录方式,无密码登录,修改密码:
1、执行以下命令
vi /etc/my.cnf
2、找[mysqld],在下面添加如下内容:
[mysqld] skip-grant-tables
3、重启mysql:
service mysqld restart
4、无密码登录mysql
[root@iZuf655czz7lmtn8v15tsjZ mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.7.28 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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>
5、执行以下命令,本以为顺风顺水,然鹅。。。
update mysql.user set Password=PASSWORD('123456') where USER='root';
。。。
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
6、看下这个 mysql.user 表里是些啥。。。
select * from mysql.user;
看来看去就这个列名顺眼:
于是我改了下语句:
mysql> update mysql.user set authentication_string=PASSWORD('123456') where USER='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
。。。wtf(原来,mysql5.7更改密码应该采用命令ALTER USER
'root'
@
'localhost'
IDENTIFIED BY
'********'其中密码的命名规则有所改变:
MySQL 设置的密码中必须至少包含一个大写字母、一个小写字母、一个特殊符号、一个数字,密码长度至少为8位)
7、好在改完了,接下来执行回退,回到/etc/my.cnf中删除新增的skip-grant-tables重启即可