安装Yum Repository

  1. [root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm

Mysql Yum仓库

使用rpm来安装MySQL

  1. [root@localhost ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm

使用yum安装mysql服务

  1. [root@localhost ~]# yum install mysql-server

检查是否已经设置为开机启动MySQL服务

  1. [root@localhost ~]# systemctl list-unit-files|grep mysqld
  2. mysqld.service disabled
  3. mysqld@.service disabled
  4. [root@localhost ~]# systemctl enable mysqld.service #设置开机启动
  5. Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service /usr/lib/systemd/system/mysqld.service.
  6. [root@localhost ~]# systemctl list-unit-files|grep mysqld
  7. mysqld.service enabled
  8. mysqld@.service disabled
  9. [root@localhost ~]# ps -ef|grep mysql # 查看是否启动MySQL服务
  10. root 4311 32702 0 21:07 pts/4 00:00:00 grep --color=auto mysql
  11. [root@localhost ~]# systemctl start mysqld.service #启动服务

image.png

修改添加密码

在MySQL 8.04前,执行:SET PASSWORD=PASSWORD(‘[新密码]’);但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。

  1. [root@SH1 /]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 10
  4. Server version: 8.0.17 Source distribution
  5. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '***passwd***'; #添加账号密码
  11. Query OK, 0 rows affected (0.01 sec)
  12. mysql>
  13. mysql> FLUSH PRIVILEGES; #刷新系统权限表
  14. Query OK, 0 rows affected (0.01 sec)
  15. mysql> exit;
  16. Bye
  17. [root@SH1 /]# mysql -uroot -p 验证密码生效
  18. Enter password:
  19. Welcome to the MySQL monitor. Commands end with ; or \g.
  20. Your MySQL connection id is 13
  21. Server version: 8.0.17 Source distribution
  22. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  23. Oracle is a registered trademark of Oracle Corporation and/or its
  24. affiliates. Other names may be trademarks of their respective
  25. owners.
  26. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  27. mysql>