开启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注销"color: #800000"> netstat -an|grep 3306
================================
将root用户授权给所以连接:grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';
最后一个为mysql密码"https://www.jb51.net/article/103770.htm">https://www.jb51.net/article/103770.htm
Centos7.1防火墙开放端口:https://www.jb51.net/article/103777.htm
CentOS 7开放端口:https://www.jb51.net/article/103773.htm
ubuntu 15.04 mysql开放远程3306端口:https://www.jb51.net/article/103784.htm
https://www.jb51.net/article/103766.htm
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)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 曾轶可.2011-一只猫的旅行【天娱传媒】【WAV+CUE】
- 黑神话悟空上品狼刺客精魄获取方法一览|上品狼刺客精魄收集攻略
- 视觉小说《神椿市建设中REGENERATE》将于2025年2月20日发售
- 黑神话悟空上品鼠弩手精魄获取方法一览|上品鼠弩手精魄收集攻略
- 中国音乐地图听见世界非物质文化遗产《非遗HQCD》wav
- 中国民乐合奏作品集《华夏之音HQ》头版限量编号[WAV+CUE]
- [电影原声带]黎允文《天将雄师》[FLAC+CUE]
- 曝NS继任机型已进入量产阶段:已花了30亿日元
- 不是Switch2?曝《马里奥惊奇》NS捆绑包即将公开
- 暖心任天堂!网友Switch维修返还时贴纸被完好保留
- 《国语老歌 经典对唱情歌 2CD》[WAV/分轨][1.1GB]
- 《刀郎 翻唱精选华语专辑 披着羊皮的狼 》[WAV+CUE][430MB]
- 《真的田震 中国乐坛红极一时的歌者 精品集》[WAV+CUE][300MB]
- 群星.1995-新滚石九大天王之情歌大全【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·纵夏欢唱【滚石】【WAV+CUE】