新装mysql8 并开启外网连接
1. 数据库安装
sudo apt-get update && sudo apt-get install mysql
2. 修改配置文件,允许外网ip访问
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
注释掉bind-address
这一行,将其修改为:
# bind-address = 127.0.0.1
bind-address = 0.0.0.0
3. 连接数据库(此时数据无密码)
mysql -u root -p
回车键进入
4. use mysql
5. 创建新用户
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
6. 更改密码加密方式
update user set plugin='mysql_native_password' where user='cordchat';
FLUSH PRIVILEGES;
7. 重启服务
sudo service mysql restart