MySQL只有information_schema一个数据库

背景:centos新安装的mysql数据库。使用DbEaver连接mysql库时,发现左边不显示表。使用命令框mysql -uroot回车登录时,发现只能看到information_schema一个数据库了。

原因:
  因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来

解决:

1.关闭mysql

  service mysql stop  或  systemctl stop mysql    或  systemctl stop mysqld

2.屏蔽权限:如下图所示

  直接输入命令: mysqld_safe --skip-grant-table

  屏幕出现: mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

3.新开起一个终端操作

    登录:mysql -u root mysql;

                  show databases; 

                  use mysql;

       查看:select host,user,password from user where user='root';

       修改密码:update user set Password=password('root') where User='root';//我设置的密码是root;

  删除空账号: delete from user where USER='';

  mysql> FLUSH PRIVILEGES;  //记得要这句话,否则如果关闭先前的终端,又会出现原来的错误

  mysql>quit

这时候就能正常连接并显示了。

猜你喜欢

转载自blog.csdn.net/u014285237/article/details/130675742