如何通过网络yum源安装MySQL

近日想在本地搭建MySQL的环境,准备工作和安装过程如下:

1. 软件环境:

CentOS 7

MySQL 5.6

2. Linux环境安装方式比较:

安装方式
优点
缺点

源码包编译安装

可量身定制软件的功能模块;

源码编译可选参数多,易出错;
编译安装过程耗时较长;
不具备软件管理功能;

RPM安装(RedHat Package Manager)

提供软件管理功能,安装、升级、卸载;
操作方便、快捷;

包间依赖;

yum安装(Yellow dog Updater,Modified)

支持在线、离线两种方式;
自动解决依赖关系;

3. yum介绍

在开始安装之前,先来了解下yum的常用命令和相关的配置。

3.1 yum常用命令

查询软件安装情况

yum list installed #查询已安装的软

yum list installed|grep package #查询具体某软件是否安装

安装软件

yum install packageName #在线安装软件包

yum localinstall packageName.rpm #本地安装

更新软件

yum list updates #列出可更新升级的软件

yum update package_name #更新软件

卸载软件

yum remove package_name #只删除软件包,保留配置文件和数据文件;

yum erase package_name #删除软件和它所有的文件。

3.2 创建网络yum源

要搭建yum源,需要先了解以下配置文件和相关目录。

/etc/yum.conf #yum的配置文件,配置缓存路径,日志路径和gpg检查

/etc/yum.repos.d/ #自定义的仓库

/var/log/yum.log #yum日志

/var/cache/yum/ #存储下载的rpm包

yum.conf配置文件,主要分为两部分,[main]部分配置全局变量;第二部分,用于配置仓库服务器,这部分也可以在/etc/yum.repos.d/目录下,保存为.repo的文件进行配置。

以下信息为/etc/yum.conf内容:

[root@Durian etc]# nl yum.conf

1 [main]

2 cachedir=/var/cache/yum/$basearch/$releasever

3 keepcache=0

4 debuglevel=2

5 logfile=/var/log/yum.log

6 exactarch=1

7 obsoletes=1

8 gpgcheck=1

9 plugins=1

10installonly_limit=5

11bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum

12distroverpkg=centos-release

13# This is the default, if you make this bigger yum won’t see if the metadata

14# is newer on the remote and so you’ll “gain” the bandwidth of not having to

15# download the new metadata and “pay” for it by yum not having correct

16# information.

17# It is esp. important, to have correct metadata, for distributions like

18# Fedora which don’t keep old packages around. If you don’t like this checking

19# interupting your command line usage, it’s much better to have something

20# manually check the metadata once an hour (yum-updatesd will do this).

21# metadata_expire=90m

22# PUT YOUR REPOS HERE OR IN separate files named file.repo

23# in /etc/yum.repos.d

在了解了以上知识后,开始着手创建Mysql的仓库文件。

cd /etc/yum.repos.d/

touchmysql-community.repo

vimysql-community.repo

在该文件中添加以下信息:

#Enable to use MySQL 5.6

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

enabled=1 #0为关闭yum源,1为开启yum源

gpgcheck=0 #0为不需要验证软件包,1为需要验证软件包

gpgkey=

4. 安装Mysql

配好了repository,也知道了yum的命令,就可以安装啦!

简单的执行yum install mysql,轻轻松松一个命令搞定!

接下来就可以使用Mysql啦!

安装好后,查看缓存目录/var/cache/yum下的文件,可以查看到get的rpm包。

:http://www.linuxidc.com/Linux/2017-10/147258.htm