下载安装
sudo apt update # 加上上面的长串
sudo apt install -y mysql-server
# 不添加密码直接进
sudo mysql -uroot
# 使用sql修改密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
# 再登陆
sudo mysql -uroot -p123456
设置远程连接
use mysql;
select user,host from user;
# 修改root的host为% 即无论在哪台主机上都能够登陆
update user set host='%' where user='root' and host='localhost';
# 修改加密规则
alter user 'root'@'%' identified with mysql_native_password by 'abc123';
# 刷新权限
flush privileges;
# 注释掉或者改为0.0.0.0
vim /etc/mysql/mysql.conf.d/mysqld.cnf
# bind-address = 127.0.0.1
# 退出重启
sudo service mysql restart #重启mysql服务
# 如果不行尝试这个
grant all privileges on *.* to root@'%' with grant option;
flush privileges;
测试mysql
登录,看是否可以正常登录以及正常使用