Linux上mysql第一次启动无密码直接登录原因以及解决 附mysql第一次启动ERROR 1045 (28000)解决方法

直接结论:

因为你之前装了mariadb,它是mysql的姊妹软件,装了它第一次登录是不需要密码的,就导致再装mysql也不需要密码。

解决:

rm -rf /var/lib/mysql

再重启mysqld就有了。

正常安装mysql第一次启动的流程是这样:

安装好mysql后先启动mysql

systemctl start mysqld

然后输入mysql发现需要密码

[root@haha ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

这时候就要查找系统给我们的临时密码

[root@haha ~]# grep password /var/log/mysqld.log 
2022-09-29T08:14:19.857571Z 0 [Note] Shutting down plugin 'sha256_password'
2022-09-29T08:14:19.857574Z 0 [Note] Shutting down plugin 'mysql_native_password'
2022-09-29T08:14:20.497908Z 1 [Note] A temporary password is generated for root@localhost: RT1:YspmNAsT (这里就是第一次登录系统给我们的临时密码 每个人临时密码都不一样)
2022-09-29T08:14:25.302837Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

用临时密码登录:

[root@haha ~]# mysql -u root -p
Enter password: 
(输入临时密码,不会显示,所以最好照着敲)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.39

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> 
(这样就进入mysql了)

输入quit可以退出mysql。

mysql> quit
Bye
[root@haha ~]#

然后也可以在mysql外面改密码,输入如下:

mysqladmin -uroot -p'RT1:YspmNAsT' password '你的密码'

注意密码要复杂点,不然会提示你更改密码失败

mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'

你可能感兴趣的:(mysql,linux,数据库,运维)