1.安装apt存储库
默认的apt是搜不到mysql的
#前置依赖
apt-get install gnupg -y
wget https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb
#默认选择ok即可
dpkg -i mysql-apt-config_0.8.20-1_all.deb
#更新存储库
apt-get update
#安装mysql
apt-get install mysql-server -y
2. 安装mysql8
一路过即可,要注意下图选项,选项1(加密方式为caching_sha2_password),会导致版本过旧的的数据库连接工具连不上,看自己情况选择,此处选2(加密方式为mysql_native_password)
3.允许远程登录
进入mysql 设置远程登录账号,此处直接设置root为远程登录了
#输入密码
mysql -u root -p
update mysql.user set host='%' where user='root';
flush privileges;
#创建用户 with mysql_native_password
CREATE USER 'zjy'@'%' IDENTIFIED with mysql_native_password BY '123';
grant all privileges on *.* to 'zjy'@'%' ;
flush privileges;
#创建用户 with caching_sha2_password
CREATE USER 'zjy2'@'%' IDENTIFIED with caching_sha2_password BY '123';
grant all privileges on *.* to 'zjy2'@'%' ;
flush privileges;
#创建用户 不写加密方式的话会选用步骤2选择的默认加密方式
CREATE USER 'zjy3'@'%' IDENTIFIED BY '123';
grant all privileges on *.* to 'zjy3'@'%' ;
flush privileges;