ubuntu 16.04 mysql5.7.17 开放远程3306端口

原创 2017年01月19日 20:33:27

开启mysql的远程访问权限

默认mysql的用户是没有远程访问的权限的,因此当程序跟数据库不在同一台服务器上时,我们需要开启mysql的远程访问权限。

主流的有两种方法,改表法和授权法。

相对而言,改表法比较容易一点,个人也是比较倾向于使用这种方法,因此,这里只贴出改表法

1、登陆mysql

 

[plain] view plain copy
 
  1. mysql -u root -p  

2、修改mysql库的user表,将host项,从localhost改为%。%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip,比如可以将localhost改为192.168.1.123,这表示只允许局域网的192.168.1.123这个ip远程访问mysql。

 

 

[plain] view plain copy
 
  1. mysql> use mysql;   
  2. mysql> select host,user form user;  
  3. mysql>update user set host = '%' where user ='root';  
  4. mysql>select host,user from user;  
  5. mysql> flush privileges;  
  6. mysql> quit;  

 

 

首先查看端口是否打开 netstat -an|grep 3306

 

打开mysql配置文件vim /etc/mysql/mysql.conf.d/mysqld.cnf

将bind-address = 127.0.0.1注销​

重启动ubuntu

再次查看端口是否打开 netstat -an|grep 3306


================================

 

 

将root用户授权给所以连接: grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';

最后一个为mysql密码​

让权限立即生效:flush privileges;​


到此所以操作完成,可以在任何主机连接此mysql数据库服务器了。


MySQL远程连接不上的解决:http://www.linuxdiyf.com/linux/11488.html

Centos7.1防火墙开放端口:http://www.linuxdiyf.com/linux/14840.html

CentOS 7开放端口:http://www.linuxdiyf.com/linux/9410.html

ubuntu 15.04 mysql开放远程3306端口:http://www.linuxdiyf.com/linux/15206.html

 

 

http://www.cnblogs.com/Struts-pring/p/5407509.html

 

 

[plain] view plain copy
 
  1. root@3bc476b7e0d5:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf  
  2. root@3bc476b7e0d5:~# netstat -an | grep 3306  
  3. tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN  

[plain] view plain copy
 
  1. root@3bc476b7e0d5:/# service mysql enable  
  2. Usage: /etc/init.d/mysql start|stop|restart|reload|force-reload|status  
  3. root@3bc476b7e0d5:/# netstat -an | grep 3306  
  4. tcp6       0      0 :::3306                 :::*                    LISTEN       
  5. root@3bc476b7e0d5:/# mysql --version  
  6. mysql  Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using  EditLine wrapper  
  7. root@3bc476b7e0d5:/# mysql -u root -p  
  8. Enter password:   
  9. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  10. Your MySQL connection id is 4  
  11. Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu)  
  12.   
  13. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.  
  14.   
  15. Oracle is a registered trademark of Oracle Corporation and/or its  
  16. affiliates. Other names may be trademarks of their respective  
  17. owners.  
  18.   
  19. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  20.   
  21. mysql> show databases;  
  22. +--------------------+  
  23. | Database           |  
  24. +--------------------+  
  25. | information_schema |  
  26. | fabric             |  
  27. | mysql              |  
  28. | performance_schema |  
  29. | sys                |  
  30. +--------------------+  
  31. 5 rows in set (0.02 sec)  
posted on 2017-11-15 10:44  艾恩格朗特  阅读(296)  评论(0编辑  收藏  举报