一、在线快速安装
1、安装yum源
首先在mysql官网上找到对应centos版本的yum源,https://dev.mysql.com/downloads/repo/yum/。
tips:centos8只能安装mysql8。
[root@compute-01 ~]# cat /etc/redhat-release #本机是centos7的环境,所以需要下载对应的yum包;
CentOS Linux release 7.7.1908 (Core)
[root@compute-01 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@compute-01 ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm #安装yum源
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
#可以手动修改使能mysql5.7或者mysql8
[root@compute-01 ~]# vim /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
**enabled=1**
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
**enabled=0**
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
也可以使用yum修改
[root@compute-01 ~]# yum-config-manager --enable mysql57-community
[root@compute-01 ~]# yum-config-manager --disable mysql80-community
安装mysql
[root@compute-01 ~]# yum install mysql-server -y
二、使用rpm包离线安装mysql
在mysql官网https://dev.mysql.com/downloads/下载相应的rpm包。
选取想要安装的版本和系统环境,下载相应的包
三、启动mysql
[root@compute-01 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@compute-01 ~]# systemctl start mysqld
[root@compute-01 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-08-17 16:32:02 CST; 3s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 18410 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 18354 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 18412 (mysqld)
Tasks: 27
Memory: 319.0M
CGroup: /system.slice/mysqld.service
└─18412 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 17 16:31:55 compute-01 systemd[1]: Starting MySQL Server...
Aug 17 16:32:02 compute-01 systemd[1]: Started MySQL Server.
tips:mysql5的密码是通过自动生成保存在mysql日志里,文件路径是:/var/log/mysqld.log
[root@compute-01 ~]# cat /var/log/mysqld.log | grep pass
2021-08-17T08:31:59.273120Z 1 [Note] A temporary password is generated for root@localhost: 73*6SM*7zZd5
root@compute-01 ~]# mysql -uroot -p
Enter password: #需要使用日志里的密码登录
mysql> alter user root@localhost identified by 'XXXXXXXX'; 登录mysql后首先需求修改密码,密码强度需要符合相关策略;