mysql 远程登录成功了 但是本地连接却找不到数据库

liyingju001 2014-04-30 09:29:13
1号机没有固定ip,2号机是有固定ip的LAMP系统,本来2号机运行正常,现在终于实现了1号机远程连接2号机的数据库;并且能够显示2号机数据库内容,做法是mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>FLUSH RIVILEGES; service iptables stop
但是问题出现了 1号机依然能显示2号机数据库的内容,并且正确。但是2号机执行mysql,showdatabases;没有原先的数据库,也没有user等数据库了,压根就不显示了 谁知道是怎么回事呢?
...全文
3038 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_30382019 2016-09-21
  • 打赏
  • 举报
回复
qq_30382019 2016-09-21
  • 打赏
  • 举报
回复
123
qq_30382019 2016-09-21
  • 打赏
  • 举报
回复
liyingju001 2014-05-05
  • 打赏
  • 举报
回复
linux的mysql下看不到mysql数据库解决方案 [root@localhost ~]# mysql -uroot -p123 Welcome to the MySQL monitor. Commands end with ; 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 the buffer. mysql>show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | +--------------------+ 只显示这个两个数据库,看不到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 end with ; 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 the buffer. 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','','','','',0,0,0,0); 如果已经存在了host为localhost的记录,则先删除该记录,delete from user where host='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','','','','',0,0,0,0);//Y的数量都不对 待修正 操作。 操作完成后,将两个ssh连接都关闭,然后再重新连接一个ssh,启动mysql,service mysqld start,然后用mysql命令连接mysql数据库 [root@localhost ~]#mysql -uroot -p 密码为空。 [如果此时还连接不上,再重启一下mysql就好了,service mysqld restart]。 然后就可以用 [root@localhost ~]#mysqladmin -uroot password 'newpassword' 来设置密码了。//一定要记得有此步骤哦
liyingju001 2014-04-30
  • 打赏
  • 举报
回复

这是修改前的状态 但是mysql -uroot -p xxxxxx;
show databases;
use mysql;
show tables;
show user;
select host from user where user='root';
//发现已经有了%;

flush privileges;
service iptables stop;
之后只要输入mysql ;show databases ;就成了
liyingju001 2014-04-30
  • 打赏
  • 举报
回复
引用 1 楼 ACMAIN_CHM 的回复:
update user set host = '%' where user = 'root'; 这样你的本地就没有root@localhost 了,需要把这个添加上。
咋添加?
ACMAIN_CHM 2014-04-30
  • 打赏
  • 举报
回复
update user set host = '%' where user = 'root'; 这样你的本地就没有root@localhost 了,需要把这个添加上。

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧