修改mysql默认密码

在Linux安装好MySQL后,首次登陆输入root没法用

Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

因为MySQL要么是直接回车要么需要找随机生成的串作为密码,

1.1找随机生成的串作为密码

vim /root/.mysql_secret

 拷贝其中的串作为登陆密码

1.2直接回车

 我恰好是不需要找字符串,只需要回车即可

[root@localhost /]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.42 sec)

2修改密码

MariaDB [(none)]> set password for 'root'@'localhost'=password('root');
Query OK, 0 rows affected (0.08 sec)

猜你喜欢

转载自blog.csdn.net/zhou_438/article/details/88943333