ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
当我输入root登录输入密码就会出现这种错误,不输入密码就可以登录,不输入密码里面只有information_scheme和test两个库。
然后我使用安全登录,这里注意要先关闭mysql服务
#关闭mysql
[root@localhost bin]# systemctl stop mariadb
#安全模式启动
[root@localhost bin]# mysqld_safe --skip-grant-tables &
mysql
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
#我这里localhost没有密码,必须要设置密码
MariaDB [mysql]> select Host,User,Password from user;
+-----------------------+------+-------------------------------------------+
| Host | User | Password |
+-----------------------+------+-------------------------------------------+
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost.localdomain | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | root | |
| localhost.localdomain | | |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.01 sec)
MariaDB [mysql]> update user set Password='root' where Host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mysql]> select Host,User,Password from user;
+-----------------------+------+-------------------------------------------+
| Host | User | Password |
+-----------------------+------+-------------------------------------------+
| % | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost.localdomain | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | root | root |
| localhost.localdomain | | |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
弄完之后就可以使用root登录了