红联Linux门户
Linux帮助

linux的mysql下看不到mysql数据库解决方案

发布时间:2017-06-16 15:16:45来源:linux网站作者:m15712884682
运行:
[root@localhost ~]# mysql -uroot -p123
Welcome to the mysql monitor.  Commands endwith ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear thebuffer.
mysql>show databases;
linux的mysql下看不到mysql数据库解决方案
只显示这个两个数据库,看不到mysql数据库。
 
解决方法:
此问题实际上是用户没有权限:
1.关闭mysql,service mysqld stop
2.启动mysql: mysqld_safe --skip-grant-tables
3.再打开一个ssh连接服务器,进行mysql操作
[root@localhost ~]#mysql
Welcome to the MySQL monitor.  Commands endwith ; or \g.
Your MySQL connection id is 7
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear thebuffer.
mysql>show databases;
在这个模式下是可以看到mysql数据库的。
在数据库名mysql下的user表中,修改相应权限,比如:
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', '', '');
如果已经存在了host为localhost的记录,则先删除该记录,delete from user wherehost='localhost';
然后再进行:
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', '', '');
操作。
操作完成后,将两个ssh连接都关闭,然后再重新连接一个ssh,启动mysql,service mysqldstart,然后用mysql命令连接mysql数据库:
[root@localhost ~]#mysql -uroot -p
密码为空。
[如果此时还连接不上,再重启一下mysql就好了,service mysqldrestart]。
然后就可以用 [root@localhost ~]#mysqladmin -urootpassword 'newpassword' 来设置密码了。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31532.html