项目场景:
ubuntu 安装mysql 8.0
1.apt 安装
2.改密码
3.vim /etc/mysql/mysql.conf.d/mysqld.cnf 改bind-address=0.0.0.0
sudo apt-get update #更新源
sudo apt-get install mysql-server #安装
sudo mysql -u root -p # -u 指定用户名 -p需要输入密码
# sudo mysql #可以不需要指定用户名密码
use mysql;
# UPDATE mysql.user SET host='%' WHERE user='root' AND host='localhost';
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '改密码';
exit;
# 远程访问
# MySQL配置文件路径
config_file="/etc/mysql/mysql.conf.d/mysqld.cnf"
# 修改bind-address
sed -i 's/^bind-address\s*=.*/bind-address = 0.0.0.0/' "$config_file"
# 重启MySQL服务
service mysql restart