MySQL数据库远程链接配置

1336
0

大哥很IT 数据老手Lv5

发表于2020-5-25 10:05

楼主
前言
当前mysql版本为5.7,执行正文下面的语句报错:
  1. You have an error in your SQL syntax; check the manual that corresponds to your
  2. MySQL server version for the right syntax to use near 'IDENTIFIED BY 'xxxxxx'
  3. WITH GRANT OPTION' at line 1

  4. 去掉identified by '密码'。
复制代码
这类问题,注意mysql相应版本支持的语法。
新建用户
格式:
  1. create user '用户名'@'localhost' identified by '密码';
复制代码
eg:
  1. 1.mysql->create user 'test'@'localhost' identified by '123';
  2. 2.mysql->create user 'test'@'192.168.7.22' identified by '123';
  3. 3.mysql->create user 'test'@'%' identified by '123';
复制代码
host="localhost"为本地登录用户,
host="ip"为ip地址登录,
host="%",为外网ip登录
删除用户
格式:
  1. drop user '用户名'@'host';
复制代码
host为创建用户时的host
eg:
drop user 'wj'@'localhost';
授权
格式:
  1. grant privileges on databasename.tablename to 'username'@'host' IDENTIFIED BY 'PASSWORD';
复制代码
eg:
  1. /*授予用户通过外网IP对于该数据库的全部权限*/

  2.   grant all privileges on `test`.* to 'test'@'%' ;

  3.   /*授予用户在本地服务器对该数据库的全部权限*/

  4.   grant all privileges on `test`.* to 'test'@'localhost';   

  5.    grant select on test.* to 'user1'@'localhost';  /*给予查询权限*/

  6.    grant insert on test.* to 'user1'@'localhost'; /*添加插入权限*/

  7.    grant delete on test.* to 'user1'@'localhost'; /*添加删除权限*/

  8.    grant update on test.* to 'user1'@'localhost'; /*添加权限*/

  9.   flush privileges; /*刷新权限*/
复制代码
但是,配置好后,还是访问不了。又查了资料,全都说就是这样设置的。
最后发现,防火墙开启的,关闭后,就可以访问啦!!

如果在配置好数据库时后并未指定被访问的数据库时,或指定其它数据库时,使用如下命令完成设置
  1. grant all privileges on 'dataName'.* to <a href="mailto:'userName'@'%'">'userName'@'%'</a>
复制代码
若是在root账户授权远程访问,首先找到mysql数据库->user表,更改Host为%,然后输入命令
  1. GRANT ALL PRIVILEGES ON 'dataName'.* TO 'root'@'%' WITH GRANT OPTION;
  2. FLUSH PRIVILEGES
复制代码
本文来源于网络

最近看过此主题的会员

zly_2960

pandabuxizao

chestnut

qwz

usery

liulei6511

hero851815

Yuuuu

小张同学

tc1998

123qweq6

linjia11lu

0个回答

只看楼主

登录后可回答问题,请登录注册

快速回复 返回顶部 返回列表

小时

全天响应

分钟

快速处理问题

工程师强势助力

明星产品
解决方案
联系合作

渠道咨询电话:137-0120-6790

技术支持QQ:400-0011-866(工作日9:00-18:00)

产品建议邮箱yixin@esensoft.com

关注我们

扫TA学习更多干货

一对一专家交流

版权所有© 2006-2024 北京亿信华辰软件有限责任公司 京ICP备07017321号 京公网安备11010802016281号