mysql安装文档
安装
| 1 | apt-get install software-properties-common | 
使用service 启动、关闭MySQL服务
| 1 | service mysql start | 
修改root权限
| 1 | mysql -u root -p | 
两种
- 改表法 
 可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称”%”- 1 
 2
 3
 4- mysql -u root -p 
 use mysql;
 update user set host = '%' where user = 'root';
 select host, user from user;
- 授权法 
 赋予任何主机访问数据的权限 :- 1 - GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION 
修改生效 :mysql>FLUSH PRIVILEGES
结果出现,就OK了:1
2
3
4
5
6
7
8+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | debian-sys-maint |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+
无法远程连接MySQL服务器
要在Linux终端中测试远程MySQL连接:1
mysql -u username -h 192.16.8.1.22 -p
或者通过WIndows的Telnet:1
telnet 192.16.8.1.22 3306
如果在尝试连接到远程MySQL服务器时遇到错误1
ERROR 2003 (HY000): Can't connect to MySQL server on '192.16.8.1.22' (111)
或者在Telnet中1
Connecting To 192.16.8.1.22...Could not open connection to the host, on port 3306: Connect failed
检查防火墙
首先,如果ufw启用了防火墙,请确保您有MySQL规则1
sudo ufw allow mysql
重启服务1
sudo service ufw restart
检查MySQL配置
您可能需要bind-address在MySQL配置文件中  注释掉mysqld.cnf1
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到行bind-address  (CTRL+ W搜索)1
/etc/mysql/mysql.conf.d/mysqld.cnf
| 1 | # | 
以上行告诉MySQL只接受本地连接。通过#在它之前添加来注释掉这一行。
重新启动MySQL服务以使更改生效。1
sudo service mysql restart