MySQL远程访问权限的设置
今儿有位同事提出,一套MySQL 5.6的环境,从数据库服务器本地登录,一切正常,可是若从远程服务器访问,就会报错,
ERROR 1045 (28000): Access denied for user 'bisal'@'x.x.x.x' (using password: YES)
我才开始接触MySQL,因此每一个错误场景,都是增长经验的机会,这种错误要么是密码错误,要么是未设置远程IP访问权限。
我们模拟下这个过程,首先,创建用户bisal,如果密码不加引号会报错,
mysql> create user bisal identified by bisal;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'bisal' at line 1
创建完成,可以看出,用户bisal的host是%,不是具体某个IP,
mysql> create user bisal identified by 'bisal';
Query OK, 0 rows affected (0.00 sec)
mysql> select user, password, host from user;
+-------+-------------------------------------------+-----------------+
| user | password | host |
+-------+-------------------------------------------+-----------------+
...
| bisal | *9AA096167EB7110830776F0438CEADA9A7987E31 | % |
+-------+-------------------------------------------+-----------------+
实验一:让指定IP访问数据库
假设数据库服务器IP是x.x.x.1,授权让x.x.x.3用户可以访问,
mysql> grant all privileges on *.* to 'bisal'@'x.x.x.3';
Query OK, 0 rows affected (0.00 sec)
此时从x.x.x.2上访问数据库,就会提示错误,因为仅允许x.x.x.3服务器,可以访问数据库,
mysql -h x.x.x.1 -ubisal
ERROR 1045 (28000): Access denied for user 'bisal'@'app' (using password: YES)
授权让x.x.x.2用户可以访问,
mysql> grant all privileges on *.* to 'bisal'@'x.x.x.2' identified by 'bisal';
Query OK, 0 rows affected (0.00 sec)
此时从x.x.x.2上,就可以访问数据库了,
mysql -h x.x.x.1 -ubisal -pbisal
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1008
Server version: 5.6.31-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 its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
实验二:让所有IP访问数据库
首先,收回刚才的授权,
mysql> revoke all privileges on *.* from bisal@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for bisal;
+--------------------------------------------------------------------------------------------+
| Grants for bisal@% |
+--------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bisal'@'%' IDENTIFIED BY PASSWORD '*9AA096167EB7110830776F0438CEADA9A7987E31' |
+--------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
此时从x.x.x.2访问数据库,会提示错误,
mysql -h x.x.x.x -ubisal -pbisal
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 997
Server version: 5.6.31-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 its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
ERROR 1044 (42000): Access denied for user 'bisal'@'%' to database 'mysql'
此时授予%所有机器访问权限,
mysql> grant all privileges on *.* to 'bisal'@'%' identified by 'bisal';
Query OK, 0 rows affected (0.00 sec)
从x.x.x.2访问数据库,此处的报错,是因为未输入密码,
mysql -ubisal
ERROR 1045 (28000): Access denied for user 'bisal'@'localhost' (using password: YES)
但如果之前设置的密码,和输入的密码不同,还是会提示错误,
mysql> grant all privileges on *.* to 'bisal'@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)
[root@vm-kvm11853-app ~]# mysql -h x.x.x.129 -ubisal -pbisal
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'bisal'@'vm-kvm11853-app' (using password: YES)
使用正确的密码登录,一切正常了,
mysql -ubisal -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 987
Server version: 5.6.31-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 its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
总结:
1. MySQL中可以设置某个IP访问权限,也可以设置%所有IP访问权限。、
2. grant all privileges ... identified by 'password',此处的password可以不是这用户的密码,远程访问以这个密码为准。
3. create user设置密码,需要用引号括起来,否则会提示语法错误。
4. create user用户不加@信息,则默认创建的用户host是%。
如果您觉得此篇文章对您有帮助,欢迎关注微信公众号:bisal的个人杂货铺,您的支持是对我最大的鼓励!共同学习,共同进步:)
MySQL远程访问权限的设置相关推荐
- MySQL远程访问权限,允许远程连接的开启
MySQL远程访问权限,允许远程连接的开启 1.登陆mysql数据库 mysql -u root -p 查看user表 www.2cto.com mysql> us ...
- 开启MySQL远程访问权限 允许远程连接
开启MySQL远程访问权限 允许远程连接 1.登陆mysql数据库 mysql -u root -p 2.使用数据库 use mysql; 3.查看数据库所有用户和密码 select host,use ...
- mysql远程访问权限开启
怎么给mysql开启远程访问权限 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改项,从"localhost&qu ...
- mysql远程访问权限_MYSQL开启远程访问权限的方法
1.登陆mysql数据库 mysql -u root -p 查看user表 mysql> use mysql; Database changed mysql> select host,us ...
- linux下安装jdk, mysql,tomcat等application示例,并且开启MySQL远程访问权限
Linux软件安装 jdk,mysql,tomcat 软件安装:软件在阿里云盘下载:30天内有效,如果过期,请联系我 https://www.aliyundrive.com/s/mKjz8t8oF9M ...
- 防火墙允许mysql_如何设置mysql远程访问及防火墙设置
笔者在一个实际的项目中需要MYSQL远程访问. 情景: 安装好Mysql, 本地访问正常,很奇怪局域的机器都无法访问该服务器上的MYSQL数据库. 经过资料查找 原来Mysql默认是不可以通过远程机器 ...
- Ubuntu 16.04 设置MySQL远程访问权限
第一步:修改配置文件的端口绑定 打开的目录可能会根据MySQL的版本稍有不同,可以先尝试打开/etc/mysql/my.cnf这个配置文件,若该文件不存在或文件内容为空,则尝试下面的文件路径. sud ...
- Java面试题库,mysql远程访问权限设置
阿里 mq 消息可靠性,幂等如何保证 分布式锁的实现方案比较,为什么选择 zookeeper, zookeeper 一致性协议原理 线程池参数,阻塞队列实现 一致性 Hash解决什么问题, 如何实现? ...
- Mysql远程访问权限
在阅读本文时,推荐先走读完浅谈Mysql权限控制一文. Mysql启动默认的端口3306是打开的,此时打开了mysqld的网络监听,允许用户远程通过账号密码连接本地数据库,Mysql数据库默认是允许远 ...
最新文章
- 这是一篇“团队”博客
- Delphi之面向对象的界面复用技术
- 网易云信启动“T服务”,为开发加速
- 昨天一天都没怎么看书。。。
- 结构pop_宏旺半导体总结嵌入式存储封装技术SiP、SOC、MCP、PoP的区别
- maven java jar_如何去maven仓库下载jar包
- 中移互联网副总:创新技术如何赋能企业变现突破
- 谷歌紧急修复已遭利用的新 0day
- netconsole 重定向kernel日志到远程服务器
- 微信小游戏代码包侵权的避开技巧(含处理脚本代码)
- linux卸载cognos,在Linux上实战安装Cognos
- 微信小程序引用阿里巴巴矢量图标
- 今日股市板块利好早知道,全球科技巨头聚齐联手保护云数据
- 下载网站的ICO图标方法
- webapp封装 苹果app证书
- 1050: [HAOI2006]旅行comf
- PTA 1003 我要通过! (20 分)
- 推荐一本书《亚马逊网络书店传奇》
- c语言中shift的作用,Shift是什么意思?Shift键的功能及作用有哪些?
- 03基础自绘-18手机通讯录-telwidget