为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL 可以用localhost 连接,但不能用IP连接

标签:
MySQL

重新安装mysql数据库遇到个问题,通过localhost或者127.0.0.1可以连接,但通过电脑的ip地址就连接失败,在网上查询了下,好像是因为忘记给数据库授权。解决方案如下:

在终端用root账户登录mysql;

C:\Users\you>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 193231
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. 
Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

输入命令:grant all privileges on *.* to '用户名'@'IP地址' identified by '密码';

用户名,随便起

IP,数据库所在的IP地址

identified by ‘密码’ 表示通过密码连接

mysql> grant all privileges on *.* to 'root'@'192.168.1.97' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)

执行完上述命令后用下面的命令刷新一下权限

flush privileges;

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)




点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Python工程师
手记
粉丝
11
获赞与收藏
54

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消