網上的N多方法都不全面,只有下面的第一步或第二步是不行的,必須同時執行下面兩步操作:
- 修改mysql.user表
以root
或debian-sys-maint
身份登錄mysql
$ mysql -u debian-sys-maint -p
mysql> use mysql
mysql> select Host, User from user;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'lxw'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
- 修改mysql配置文件
$ pwd
/etc/mysql/mysql.conf.d
$ vim mysqld.cnf #對應修改下面的內容
# 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 = 0.0.0.0
修改完成后,需要重新啟動mysql服務
$ /etc/init.d/mysql restart