zoukankan      html  css  js  c++  java
  • 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后就可以看到所有的数据库了。

    学无止境,你说呢?
  • 相关阅读:
    Android 屏幕适配问题分析
    Android应用程序结构
    国内市场各品牌手机后门介绍
    获取Android设备WIFI的MAC地址 “MAC地址”
    Android 如何判断指定服务是否在运行中 “Service”
    Android强制关闭某个指定应用 “关闭应用”
    如何在Android中的Activity启动第三方应用程序?
    js事件(十二)
    js文本对象模型[DOM]【续】(Node节点类型)
    js文本对象模型【DOM】(十一)
  • 原文地址:https://www.cnblogs.com/moumouLiu/p/15233414.html
Copyright © 2011-2022 走看看