Ubuntu下开启MySQL远程连接权限(新版本方法)

Ubuntu下开启MySQL远程连接权限

一、将用户的访问地址改为%

  1. 打开终端登录mysql数据库:
    mysql -u root -p
  2. 查看user表
    mysql> use mysql;
    Database changeed
    mysql>select host, user, authentication_string from user;

注意此处网上很多教程写的是password,那是老版的了,现在的MySQL的mysql数据库的user表中已经没有password字段了,而是换成了authentication_string

±----------±-----------------±------------------------------------------+
| host | user | authentication_string |
±----------±-----------------±------------------------------------------+
| localhost | root | ********************************** |
| localhost | mysql.session | ********************************** |
| localhost | mysql.sys | ********************************** |
| localhost | debian-sys-maint | *********************************** |
±----------±-----------------±------------------------------------------+
4 rows in set (0.00 sec)

  1. mysql> update user set host = '%' where user = 'root'

二、注释bind-address = 127.0.0.1

在Ubuntu系统中,MySQL默认只能本地访问,不能远程访问,因为访问地址被绑定死了为本地127.0.0.1,想要远程访问的话,需要去/etc/mysql/mysql.conf.d中找到bind-address = 127.0.0.1,然后注释掉这一句,也就是在这句前面加上#号。

然后重启MySQL就可以了。
重启命令为:service mysql restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章