yum安装MySQL
由于现在的Linux系统的默认的MySQL变成了MariaDB,因此无法直接通过默认的yum源安装MySQL数据库了,下面为大家介绍一下如何在当前的linux上使用yum的方式安装MySQL数据库。
一、yum安装
1.1 yum安装原理:
yum安装是通过执行yum命令,自动到yum 的repository(仓库)下载安装rpm包并自动安装依赖包。
1.2 yum安装优点:
安装简单、快速
1.3 缺点:
由于不同的yum仓库只有特定的几个版本,所以可选的版本较少。
1.4 安装实战
下面看看如何在CentOS7系统上安装MySQL5.5.60
1.4.1 系统环境
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
1.4.2 下载安装官网yum源
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
说明:官网yum仓库的MySQL都是GA版本,GA版本 注:GA- General Availability,通常可用,指可以用于生产环境的版本。
1.4.3 查看下当前可安装哪些版本
[root@localhost ~]# yum repolist all |grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 51
mysql-connectors-community-source MySQL Connectors Community - S disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 63
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - S disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - S disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - S disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 17
mysql80-community-source MySQL 8.0 Community Server - S disabled
1.4.4 将需要安装的版本改为enabled
[root@localhost ~]# sed -i 's#enabled=1#enabled=0#g' /etc/yum.repos.d/mysql-community.repo
[root@localhost ~]# sed -i '5s#enabled=0#enabled=1#g' /etc/yum.repos.d/mysql-community.repo
1.4.5 yum安装MySQL
[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# rpm -qa mysql-community-server
mysql-community-server-5.5.60-2.el7.x86_64
1.4.6 启动MySQL服务并进入MySQL交互模式
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# netstat -lntup|grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 10994/mysqld
[root@localhost ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.60 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
一键安装脚本
#!/bin/bash
#########################################################################
#function yum install MYSQL
#Author FengZhibin
#Mail 1742484684@qq.com
#########################################################################
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum repolist all
sed -i 's#enabled=1#enabled=0#g' /etc/yum.repos.d/mysql-community.repo
sed -i '5s#enabled=0#enabled=1#g' /etc/yum.repos.d/mysql-community.repo
yum -y install mysql-community-server
systemctl start mysqld
systemctl status mysqld