第一步卸载/清理残余
dpkg --list|grep mysql
根据查询首先卸载以前的数据库
sudo apt-get remove mysql-common
第二步 安装Mysql
更新一下列表
sudo apt-get update
安装mysql
sudo apt-get install mysql-server
登录mysql
mysql -u root -p
登录默认没有密码直接回车
使用mysql数据库
use mysql;
开启远程连接
update user set host='%' where user='root' and host='localhost';
修改了之后刷新以下权限
flush privileges;
修改数据库密码
ALTER USER 'root'@'%' identified with mysql_native_password BY '你的密码';
修改了之后刷新以下权限
flush privileges;
退出数据库
exit
下载firewalld
apt install firewalld
配置3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙
firewall-cmd --reload
查看那些端口是开启的
firewall-cmd --list-port
修改mysql配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address = 127.0.0.1注释掉,或者改成允许连接的IP地址