0
点赞
收藏
分享

微信扫一扫

mysql授权远程登录

远程客户端直接连接失败,因为没开远程连接权限

[root@xuegod14 ~]# mysql -uroot -p -h192.168.6.13 -P3306
Enter password: 
ERROR 1130 (HY000): Host '192.168.6.14' is not allowed to connect to this MySQL server

开发如果想远程登录数据库,向运维或者DBA申请。如下在服务端操作

[root@tech_master01 ~]# mysql -S /my_mysql/3306/mysql.sock -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.40-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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>
# 授权SQL语句,允许root用户在指定的网段内可以登录该数据库。注:此处密码是远程登录时用的密码,可以与本机登录时设置的密码不一样。
mysql> grant all privileges on *.* to root@'192.168.6.%' identified by '111111';
Query OK, 0 rows affected (0.01 sec)

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

远程客户端再次尝试,登录成功

[root@xuegod14 ~]# mysql -uroot -p -h192.168.6.13 -P3306
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.40-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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>
举报

相关推荐

0 条评论