Mariadb不显示mysql数据库问题排查

2021/9/6 19:09:20

本文主要是介绍Mariadb不显示mysql数据库问题排查,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

现象

安装mariadb-server后,使用systemctl start mariadb启动mariadb,并使用mysql -uroot -p登录数据库。
执行show databases;命令查看数据库,发现只有information_schema和test数据库:

\# mysql -u root -p
Enter password: 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+

2 rows in set (0.00 sec)
正常情况下查看数据库应该有:information_schema;mysql;performance_schema;test四个数据库。
但是到文件系统中查看/var/lib/mysql路径下是有mysql目录的,代表mysql数据库是存在的。

# ls -l /var/lib/mysql/ |grep "^d"
drwx------. 2 mysql mysql      4096 Sep  1 12:02 mysql
drwx------. 2 mysql mysql      4096 Sep  1 12:02 performance_schema
drwx------. 2 mysql mysql      4096 Sep  1 12:02 test

解决方案

可能是没有权限导致:
尝试赋权,但是mariadb报错了。

MariaDB [information_schema]> grant all privileges on  *.* to 'root'@'localhost';
ERROR 1045 (28000): Access denied for user ''@'localhost' (using password: NO)
 MariaDB [(none)]> use information_schema;
 MariaDB [information_schema]> select * from USER_PRIVILEGES;
+----------------+---------------+----------------+--------------+
| GRANTEE        | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE |
+----------------+---------------+----------------+--------------+
| ''@'localhost' | def           | USAGE          | NO           |
+----------------+---------------+----------------+--------------+
1 row in set (0.00 sec)

查看information_schema数据库的USER_PRIVILEGES表,发现只有一条赋权数据,说明当前mariadb的赋权是有问题的。

在mariadb数据库的配置文件/etc/my.cnf的[mysqld]配置段中新增配置项skip-grant-tables,重启mariadb服务。再次登录mariadb查看数据库,可以看到所有的数据库都可见了:

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

尝试给root用户赋权可以查看所有的数据库,报错:

MariaDB [(none)]> grant all privileges on *.* to 'root'@'localhost'; 
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement  #意思是使用了配置参数--skip-grant-tables后不可以修改权限。
可以通过执行flush privileges;解决以上报错,然后执行赋权操作并给root用户配置密码:
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant all privileges on *.* to 'root'@'localhost';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> SET password for 'root'@'localhost'=password('sql123');
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit

退出数据库并将之前在/etc/my.cnf中的配置项#skip-grant-tables注释,然后重启mariadb,再次登录mariadb后就可以看到所有的数据库了。



这篇关于Mariadb不显示mysql数据库问题排查的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程