今儿有位同事提出,一套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是%。

mysql远程连接权限设置的更多相关文章

  1. 如何开启MYSQL远程连接权限

    开启MYSQL远程连接权限 //建议设置固定IP mysql> GRANT ALL PRIVILEGES ON *.* TO root@"8.8.8.8" IDENTIFIE ...

  2. 开启MYSQL远程连接权限

      开启MYSQL远程连接权限   1 2 3 4 5 //建议设置固定IP mysql> GRANT ALL PRIVILEGES ON *.* TO root@"8.8.8.8&q ...

  3. (转)Linux开启mysql远程连接的设置步骤

    Mysql默认root用户只能本地访问,不能远程连接管理mysql数据库,Linux如何开启mysql远程连接?设置步骤如下: 1.GRANT命令创建远程连接mysql授权用户itlogger mys ...

  4. mysql 远程连接权限

    当你远程连不上时,可能的原因: 1.是否开启了远程连接权限 2.是否启动了mysql服务 使用客户端远程登陆报错: 使用命令行myslq -h192.168.82.23 -uroot -p123456 ...

  5. centos6.8 配置mysql赋予mysql远程连接权限

    1.关掉防火墙 2.检查3306端口是否开放 3.修改用户用户权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '您的数据库密码' ...

  6. MYSQL远程登录权限设置 ,可以让Navicat远程连接服务器的数据库

    Mysql默认关闭远程登录权限,如下操作允许用户在任意地点登录: 1. 进入mysql,GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ...

  7. [转]MYSQL远程登录权限设置

    Mysql默认关闭远程登录权限,如下操作允许用户在任意地点登录:   1. 进入mysql,GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED B ...

  8. MYSQL远程登录权限设置(转)

    Mysql默认关闭远程登录权限,如下操作允许用户在任意地点登录: 1. 进入mysql,GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ...

  9. MYSQL远程登录权限设置

    Mysql默认关闭远程登录权限,如下操作允许用户在任意地点登录: 1. 进入mysql,GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ...

随机推荐

  1. vmware centos 安装

    一.分区 一块硬盘主分区+扩展分区最多只能有4个,其中扩展分区最多只能有1个.扩展分区不能写入数据,只能包含逻辑分区.这些都不是linux的限制,而是硬盘结构的限制. 分区号 第一种分区法: |--- ...

  2. solr学习笔记

    目录 前言 linux部署 使用 配置 使用 前言 solr是apach基于Lucene开发的成熟的框架,这里我们学习如何部署.使用.关于集群会在后面继续添加 linux部署 mkdir /usr/l ...

  3. CentOS6.4 下安装 jdk1.7.0_67

    1.卸载系统自带的jdk 1.1.查看该操作系统上是否已经安装了jdk [root@xhTest-1 ~]# rpm -qa | grep jdk 1.2.删除系统自带的jdk [root@xhTes ...

  4. 排序算法(2) 堆排序 C++实现

    堆 1 数组对象 2 可以视为一棵完全二叉树 3 一个堆可以被看作一棵二叉树和一个数组,如下图所示: 4 下标计算(通常使用内联函数或者宏来定义下标操作): 已知某个结点的下标为i 其父节点下标:i/ ...

  5. Linux 系统必须掌握的文件_【all】

    0.Linux 系统文件的详解 1.Linux 系统的网络配置文件 2.Linux 系统的DNS配置文件 3.Linux 系统的IP与域名解析文件[局域网的DNS] 4.Linux 系统的主机别名文件 ...

  6. Linux ulimit命令详解

    ulimit 是一个计算机命令,用于shell启动进程所占用的资源,可用于修改系统资源限制 命令常用参数 -H 设置硬资源限制. -S 设置软资源限制. -a 显示当前所有的资源限制. -c size ...

  7. SIM900A模块HTTP相关调试笔记

    SIM900A模块使用笔记 更新2018-12-8 正常工作状态: 接线方法: 首先将 AT 写入字符串输入框,然后点击 发送.因为模块波特率默认是 9600,所以两条指令的显示都是没有问题的:如果将 ...

  8. 数据结构&堆&heap&priority_queue&实现

    目录 什么是堆? 大根堆 小根堆 堆的操作 STL queue 什么是堆? 堆是一种数据结构,可以用来实现优先队列 大根堆 大根堆,顾名思义就是根节点最大.我们先用小根堆的建堆过程学习堆的思想. 小根 ...

  9. 【转】.net core 一次坑爹的类库打包过程

    自己遇到这个问题,记录一下,原文链接:http://www.cnblogs.com/Hai--D/p/5776463.html. 众所周知,.net core 跨平台类库引用一定要通过nuget获得. ...

  10. Ceph PG介绍及故障状态和修复

    1 PG介绍pg的全称是placement group,中文译为放置组,是用于放置object的一个载体,pg的创建是在创建ceph存储池的时候指定的,同时跟指定的副本数也有关系,比如是3副本的则会有 ...