安装Yum Repository
[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
使用rpm来安装MySQL
[root@localhost ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
使用yum安装mysql服务
[root@localhost ~]# yum install mysql-server
检查是否已经设置为开机启动MySQL服务
[root@localhost ~]# systemctl list-unit-files|grep mysqld
mysqld.service disabled
mysqld@.service disabled
[root@localhost ~]# systemctl enable mysqld.service #设置开机启动
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl list-unit-files|grep mysqld
mysqld.service enabled
mysqld@.service disabled
[root@localhost ~]# ps -ef|grep mysql # 查看是否启动MySQL服务
root 4311 32702 0 21:07 pts/4 00:00:00 grep --color=auto mysql
[root@localhost ~]# systemctl start mysqld.service #启动服务
修改添加密码
在MySQL 8.04前,执行:SET PASSWORD=PASSWORD(‘[新密码]’);但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。
[root@SH1 /]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17 Source distribution
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '***passwd***'; #添加账号密码
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> FLUSH PRIVILEGES; #刷新系统权限表
Query OK, 0 rows affected (0.01 sec)
mysql> exit;
Bye
[root@SH1 /]# mysql -uroot -p 验证密码生效
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.17 Source distribution
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>