当前位置: 移动技术网 > IT编程>数据库>Mysql > ubuntu 16.04下mysql5.7.17开放远程3306端口

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

租房合同样本,爱不能从头,淘吧仔

开启mysql的远程访问权限

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

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

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

1、登陆mysql

mysql -u root -p 

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

mysql> use mysql; 
mysql> select host,user form user; 
mysql>update user set host = '%' where user ='root'; 
mysql>select host,user from user; 
mysql> flush privileges; 
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远程连接不上的解决:

centos7.1防火墙开放端口:

centos 7开放端口:

ubuntu 15.04 mysql开放远程3306端口

root@3bc476b7e0d5:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf 
root@3bc476b7e0d5:~# netstat -an | grep 3306 
tcp 0 0 127.0.0.1:3306 0.0.0.0:* listen 

root@3bc476b7e0d5:/# service mysql enable 
usage: /etc/init.d/mysql start|stop|restart|reload|force-reload|status 
root@3bc476b7e0d5:/# netstat -an | grep 3306 
tcp6 0 0 :::3306 :::* listen 
root@3bc476b7e0d5:/# mysql --version 
mysql ver 14.14 distrib 5.7.16, for linux (x86_64) using editline wrapper 
root@3bc476b7e0d5:/# mysql -u root -p 
enter password: 
welcome to the mysql monitor. commands end with ; or \g. 
your mysql connection id is 4 
server version: 5.7.16-0ubuntu0.16.04.1 (ubuntu) 
 
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> show databases; 
+--------------------+ 
| database | 
+--------------------+ 
| information_schema | 
| fabric | 
| mysql | 
| performance_schema | 
| sys | 
+--------------------+ 
5 rows in set (0.02 sec) 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网