ubuntu下的linux开启稍微有点麻烦,查了一些资料才搞定,总结一下当作以后的速查表。
1.首先,机器要开启了3306端口
1 2 |
root@iZ94vs9ps2zZ:~# netstat -an | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN |
如果前缀是127.0.0.1:3306,那至少证明没有开启端口,那如何处理呢,接下来看第二步
2.修改mysql 配置文件
1 |
cd /etc/mysql |
我们查看一下文件
1 2 3 4 5 6 7 8 |
root@iZ94vs9ps2zZ:/etc/mysql# ls -al total 32 drwxr-xr-x 3 root root 4096 Mar 30 19:40 . drwxr-xr-x 140 root root 12288 Mar 30 19:42 .. drwxr-xr-x 2 root root 4096 Mar 9 20:59 conf.d -rwxr-xr-x 1 root root 1220 Oct 22 22:23 debian-start -rw------- 1 root root 333 Nov 11 20:17 debian.cnf -rw-r--r-- 1 root root 3506 Mar 30 19:32 my.cnf |
vim my.cnf 这个文件
1 2 3 |
# Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. # bind-address = 127.0.0.1 |
bind-address 这一行需要注释掉。
3.进入mysql数据库,增加远程用户名和密码
1 2 |
root@iZ94vs9ps2zZ:/etc/mysql# mysql -u root -p Enter password: |
然后直接输入以下命令
1 |
GRANT ALL PRIVILEGES ON *.* TO 'bruce'@'%' IDENTIFIED BY 'input_your_password_here' WITH GRANT OPTION; |
bruce:用户名你需要修改的
input_your_password_here:远程的密码
on *.* 对所有库都有访问权限 ,前一个*代表库名,后一个*代表表名
4.刷新一下权限列表
1 |
flush privileges; |
OK,重启一下,让规则生效。
一般就可以链接了。