1.安装apt存储库

默认的apt是搜不到mysql的

  1. #前置依赖
  2. apt-get install gnupg -y
  3. wget https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb
  4. #默认选择ok即可
  5. dpkg -i mysql-apt-config_0.8.20-1_all.deb
  6. #更新存储库
  7. apt-get update
  8. #安装mysql
  9. apt-get install mysql-server -y

2. 安装mysql8

一路过即可,要注意下图选项,选项1(加密方式为caching_sha2_password),会导致版本过旧的的数据库连接工具连不上,看自己情况选择,此处选2(加密方式为mysql_native_password)
image.png

3.允许远程登录

进入mysql 设置远程登录账号,此处直接设置root为远程登录了

  1. #输入密码
  2. mysql -u root -p
  3. update mysql.user set host='%' where user='root';
  4. flush privileges;
  5. #创建用户 with mysql_native_password
  6. CREATE USER 'zjy'@'%' IDENTIFIED with mysql_native_password BY '123';
  7. grant all privileges on *.* to 'zjy'@'%' ;
  8. flush privileges;
  9. #创建用户 with caching_sha2_password
  10. CREATE USER 'zjy2'@'%' IDENTIFIED with caching_sha2_password BY '123';
  11. grant all privileges on *.* to 'zjy2'@'%' ;
  12. flush privileges;
  13. #创建用户 不写加密方式的话会选用步骤2选择的默认加密方式
  14. CREATE USER 'zjy3'@'%' IDENTIFIED BY '123';
  15. grant all privileges on *.* to 'zjy3'@'%' ;
  16. flush privileges;