zoukankan      html  css  js  c++  java
  • 10.26

    今天学了解决了一个MySQL问题

    1. show databases查询结果不完整

    【问题描述】:

    使用“show databases”命令查询数据库信息时,查询出来的结果没有将所有的数据库信息都显示出来,如下:

    上述查询结果只显示了数据库“information_schema”,而实际上还存在其他数据库。

    【解决方案】:

    通常,出现这种情况是因为当前登录 MySQL 的“用户/主机名”权限不足。使用“show grants”命令查询当前用户的权限,如下:

    由上述结果可得到两条信息:

     

    • 当前的mysql用户,是从“localhost”主机登录到 MySQL 服务器的;
    • 对于从“localhost”主机登录到 MySQL 服务器的mysql用户(无论哪个用户身份),都只有 USAGE 权限(即空权限)。

    根据以上两条信息,得知数据库显示结果不完整就是用户/主机名权限不足导致的,所以为了解决此问题,需要放开相应的用户/主机名的权限。

    具体的解决步骤如下:

    1. 在mysql的配置文件 /etc/my.cnf 的“[mysqld]”配置下,添加“skip-grant-tables”,跳过权限检查,如下:

    2. 重启 MySQL 服务器,如下:

    systemctl restart mysqld

    3. 再次连接 MySQL 服务器,并查看数据库信息:

    1.  
      [root@node1 ~]# mysql
    2.  
      Welcome to the MySQL monitor. Commands end with ; or g.
    3.  
      Your MySQL connection id is 3
    4.  
      Server version: 5.6.40 MySQL Community Server (GPL)
    5.  
       
    6.  
      Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    7.  
       
    8.  
      Oracle is a registered trademark of Oracle Corporation and/or its
    9.  
      affiliates. Other names may be trademarks of their respective
    10.  
      owners.
    11.  
       
    12.  
      Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    13.  
       
    14.  
      mysql> show databases;
    15.  
      +--------------------+
    16.  
      | Database |
    17.  
      +--------------------+
    18.  
      | information_schema |
    19.  
      | mysql |
    20.  
      | performance_schema |
    21.  
      | testdb |
    22.  
      +--------------------+
    23.  
      4 rows in set (0.00 sec)
    24.  
       
    25.  
      mysql>

    在上述结果中能够看到,现在已经能够正常显示所有数据库了。

    但是,这是我们跳过了权限检查的结果,而跳过权限检查可能会带来数据库安全隐患,所以我们需要通过修改 用户/主机名 的权限来从根本上解决此问题。

    4. 放开对应 用户/主机名 的权限

    MySQL 数据库的 用户/主机名 权限信息存放在数据库“mysql”下的表“user”中,如下:

    1.  
      mysql> use mysql;
    2.  
      Reading table information for completion of table and column names
    3.  
      You can turn off this feature to get a quicker startup with -A
    4.  
       
    5.  
      Database changed
    6.  
      mysql>
    7.  
      mysql> select host,user,password from user;
    8.  
      +-----------+------+----------+
    9.  
      | host | user | password |
    10.  
      +-----------+------+----------+
    11.  
      | node1 | root | |
    12.  
      | % | root | |
    13.  
      | ::1 | root | |
    14.  
      | localhost | | |
    15.  
      | node1 | | |
    16.  
      +-----------+------+----------+
    17.  
      5 rows in set (0.00 sec)
    18.  
       
    19.  
      mysql>

    在 user 表中,我们看到了主机名(host)为“localhost ”的记录,通过下面的命令删除、插入该条记录,来放开其对应的权限,如下:

    1.  
      mysql> 
    2.  
      mysql> delete from user where host = 'localhost';
    3.  
      Query OK, 1 row affected (0.00 sec)
    4.  
       
    5.  
      mysql> 
    6.  
      mysql> insert into user values('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '', 'N');
    7.  
      Query OK, 1 row affected (0.00 sec)
    8.  
       
    9.  
      mysql> select host,user,password from user;
    10.  
      +-----------+------+----------+
    11.  
      | host      | user | password |
    12.  
      +-----------+------+----------+
    13.  
      | node1     | root |          |
    14.  
      | %         | root |          |
    15.  
      | ::1       | root |          |
    16.  
      | localhost | root |          |
    17.  
      | node1     |      |          |
    18.  
      +-----------+------+----------+
    19.  
      5 rows in set (0.00 sec)
    20.  
       
    21.  
      mysql> 

    执行上述操作之后,就放开了主机名为“localhost ”、用户名为“root”的用户权限。

  • 相关阅读:
    Mybatis3.1-[tp_36-37]-_映射文件_select_resultMap关联查询__分步查询传递多列值&fetchType_discriminator鉴别器
    Mybatis3.1-[tp_34-35]-_映射文件_select_resultMap关联查询_collection定义关联集合封装规则_collection分步查询_延迟加载
    Mybatis3.1-[tp_32-33]-_映射文件_select_resultMap关联查询_association分步查询_延迟加载
    Mybatis3.1-[tp-30-31]-select_resultMap_关联查询_级联属性封装结果__association定义关联对象封装规则
    Mybatis3.0-[tp_28-29]-映射文件-resultMap_自定义结果集映射规则_及关联环境的搭建
    MyBatis3_[tp-26-27]_映射文件_select_返回List_记录封装Map:返回单个元素的Map或者整体Map集合
    MyBatis 3.0_[tp-24-25]_映射文件_参数处理_#与$取值区别_#{}更丰富的用法
    mybatis3.1-[topic-18-20]-_映射文件_参数处理_单个参数&多个参数&命名参数 _POJO&Map&TO 三种方式及举例
    mybatis3.1-[topic-16-17]-映射文件_增删改查_insert_获取自增主键的值
    通过类名获取控件数组
  • 原文地址:https://www.cnblogs.com/dty602511/p/14169988.html
Copyright © 2011-2022 走看看