Mysql数据库的远程访问设置

时间:2022-09-18 22:14:32

本篇文章意在纠正网上很多错误的博客,下面是正确的方法:

以下操作使用root权限

1、编辑mysql配置文件,注释掉“bind-address = 127.0.0.1”
    root@ubuntu:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf
    #bind-address = 127.0.0.1


2、赋权限:
    root@ubuntu:~# mysql -u root -proot 
    use database mysql;
    grant all privileges on *.* to 'username'@’%’ identified by ‘password’ with grand option;
    或者 grant all privileges on *.* to 'username'@’192.168.%.%’ identified by ‘password’ with grand option;
    或者 grant all privileges on *.* to 'username'@’192.168.1.99’ identified by ‘password’ with grand option;

3、重启mysql
    root@ubuntu:~# /etc/init.d/mysql restart 

注:远程访问数据库的图形界面软件推荐使用:HeidiSQL