• mysql5.6.50物理迁移后root登录不显示mysql库和业务库


    问题描述

    mysql5.6.50通过拷贝数据目录的方式实现物理迁移,启动目标库root登录查询数据库不显示mysql库和其他业务库。

    --登录
    [root@kaiping01 data]#mysql
    或
    [root@kaiping01 data]#mysql -uroot -p
    
    --查看数据库,发现mysql和其他业务库不显示
    root@localhost :(none) 17:54:16>show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | test               |
    +--------------------+
    2 rows in set (0.01 sec)
    
    root@localhost :(none) 18:13:34>select user();
    +----------------+
    | user()         |
    +----------------+
    | root@localhost |
    +----------------+
    1 row in set (0.00 sec)
    
    --查看权限
    root@localhost :(none) 17:54:20>show grants;
    +--------------------------------------+
    | Grants for @localhost                |
    +--------------------------------------+
    | GRANT USAGE ON *.* TO ''@'localhost' |
    +--------------------------------------+
    1 row in set (0.00 sec)
    
    root@localhost :(none) 17:54:33>exit
    
    --切换user库报错
    root@localhost :(none) 17:59:22>use mysql
    ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
    root@localhost :(none) 18:03:12>select user,host from mysql.user;
    ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    问题分析

    --采用host 127.0.0.1登录
    [root@kaiping01 log]# mysql -uroot -h 127.0.0.1
    
    --查看权限
    root@127.0.0.1 :(none) 18:01:11>show grants;
    +---------------------------------------------------------------------+
    | Grants for root@127.0.0.1                                           |
    +---------------------------------------------------------------------+
    | GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION |
    +---------------------------------------------------------------------+
    
    --查看user表
    root@127.0.0.1 :(none) 18:06:18>select user,host from mysql.user;
    +------+-----------+
    | user | host      |
    +------+-----------+
    | root | %         |
    | root | 127.0.0.1 |
    | root | ::1       |
    |      | kaiping02 |
    | root | kaiping02 |
    |      | localhost |
    +------+-----------+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    尝试的解决办法如下,均失败收尾:

    --采用host 127.0.0.1登录
    [root@kaiping01 log]# mysql -uroot -h 127.0.0.1
    
    --查看主机名
    [root@kaiping01 data]# hostname
    kaiping01
    
    --更改user表中host和操作系统的主机名一致
    select user,host from mysql.user where host='kaiping02';
    update mysql.user set host='kaiping01' where user in ('','root') and host='kaiping02';
    FLUSH PRIVILEGES;
    未解决问题
    
    --创建root@localhost用户
    root@127.0.0.1 :mysql 18:28:01>create user 'root'@'localhost' identified  by 'root';
    ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'localhost'
    创建失败未解决问题
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    问题解决

    --采用host 127.0.0.1登录
    [root@kaiping01 log]# mysql -uroot -h 127.0.0.1
    
    --更新user表,将''@'localhost'更改为'root'@'localhost'
    select user,host from mysql.user where user='' and host='localhost';
    update mysql.user set user='root' where user='' and host='localhost';
    FLUSH PRIVILEGES;
    
    --赋予权限
    grant all privileges on *.* to 'root'@'localhost' with grant option;
    FLUSH PRIVILEGES;
    
    --采用mysql或mysql -uroot -p方式登录,查询数据库
    [root@kaiping01 log]# mysql
    或
    [root@kaiping01 log]# mysql -uroot -p
    
    --查询数据库
    root@localhost :(none) 18:35:22>show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |
    | xzspkp             |
    +--------------------+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
  • 相关阅读:
    实现性别平等,我们绝不能再等132年
    ArrayList与List的层级关系及ArrayList解析
    visual studio下载安装
    支付牌照缩量,分账管理系统成为了众多电商平台寻求合规的主要途径
    在中国企业出海的大浪潮下,亚马逊云科技提供遍及全球的基础设施和技术支持
    注解、AOP
    结构体大小的计算(结构体内存对齐)
    数字秒表VHDL实验箱精度毫秒可回看,视频/代码
    【数据结构与算法】带头双向循环链表
    【Shiro】入门概述
  • 原文地址:https://blog.csdn.net/qq961573863/article/details/134252713