1、下载MySQL源安装包并安装
MySQL源安装包下载链接
或
[root@ chenc01 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[root@ chenc01 ~]# yum localinstall mysql80-community-release-el7-1.noarch.rpm
2、检查是否安装成功
[root@ chenc01 ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 141
mysql-tools-community/x86_64 MySQL Tools Community 105
mysql80-community/x86_64 MySQL 8.0 Community Server 161
3、安装mysql
[root@ chenc01 ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 5.3 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql55-community | 2.5 kB 00:00:00
updates | 2.9 kB 00:00:00
mysql55-community/x86_64/primary_db | 183 kB 00:00:00
Loading mirror speeds from cached hostfile
4、启动mysql服务
1)启动
[root@ chenc01 ~]# systemctl start mysqld
2)查看启动状态
[root@ chenc01 ~]# systemctl status mysqld
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-03-16 18:17:59 CST; 39s ago
Process: 2003 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 1949 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 2002 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─2002 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─2161 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/...
3)设置开机启动
[root@ chenc01 ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mysqld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
4)启动MySQL
注意MySQL8.0.19 的登录密码是自动生成的!
[root@ chenc01 ~]# grep 'temporary password' /var/log/mysqld.log
2020-03-16T10:33:27.273294Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: eRxeGx_AO5nZ
[root@ chenc01 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.19
Copyright (c) 2000, 2020, 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>
5)修改MySQL登录密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'TestBicon@123';
Query OK, 0 rows affected (0.01 sec)
mysql>