首先安装MySQL、mysqlclient
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysqlclient-dev
pip install mysqlclient
修改配置文件中的bind-address
文件路径:
/etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address = 127.0.0.1修改为bind-address = 0.0.0.0
重新启动并登陆mysql
sudo service mysql restart
2 mysql -uroot -p
修改权限:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
重新启动mysql
sudo service mysql restart
注意:有时重启服务器后mysql未启动导致远程无法连接只需启动mysql
sudo service mysql start
总结:这就是我在Ubuntu上的配置方法,亲测可用,可能还有其他的配置方法,仅供参考,谢谢。