国外的东西就是好,东西给你了,连教程都准备好了,可惜了我这连四级都没过的英语水平啊,没办法硬着头皮也要看哪。
看看官网给出的具体步骤:
1. 添加mysql yum 库
a. 首先要到MySQL yum库的下载页面http://dev.mysql.com/downloads/repo/yum/
b. 找一个跟自己平台匹配的发行包,用uname
命令看看自己的平台版本
c. 用wget
命令把相应的rpm包下下来,这个包很小只有几k
[root@VM_235_40_centos ~]# wget https://repo.mysql.com//mysql57-community-release-el7-9.ch.rpm
--2017-04-05 16:32:26-- https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.50.25.213
Connecting to repo.mysql.com (repo.mysql.com)|23.50.25.213|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: 'mysql57-community-release-el7-9.noarch.rpm'
100%[============================================================>] 9,224 --.-K/s in 0s
2017-04-05 16:32:28 (75.1 MB/s) - 'mysql57-community-release-el7-9.noarch.rpm' saved [9224/9224]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
d. 把这个包安装上
[root@VM_235_40_centos ~]# rpm -Uvh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5KEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-9 ################################# [100%]
[root@VM_235_40_centos ~]cd /etc/yum.repos.d
#安装完成后会发现/etc/yum.repos.d会多了两个mysql的repo文件
[root@VM_235_40_centos yum.repos.d]# ls
CentOS-Base.repo mysql-community-source.repo
CentOS-Epel.repo mysql-community.repo
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
2. 看看文件里有啥东西
[root@VM_235_40_centos yum.repos.d]# more mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# 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/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[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
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
按照官网的说法,在这个文件中你可以配置你想要安装的mysql版本,如果需要安装这个版本就设置enabled=1
,不需要的版本就把它设置为0。这里我安装5.7的版本
3. 完事具备,接下来就可以来安装mysql了
[root@VM_235_40_centos yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.17-1.el6 for package: mysql-communserver-5.7.17-1.el6.x86_64
......
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el6 will be obsoleting
--> Finished Dependency Resolution
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
Requires: libmysqlclient.so.18()(64bit)
Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@os)
libmysqlclient.so.18()(64bit)
Obsoleted By: mysql-community-libs-5.7.17-1.el6.x86_64 (mysql57-community)
~libmysqlclient.so.20()(64bit)
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@os)
libmysqlclient.so.18(libmysqlclient_18)(64bit)
Obsoleted By: mysql-community-libs-5.7.17-1.el6.x86_64 (mysql57-community)
Not found
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
纳尼,竟然安装出错,出什么鬼了。原来是mariadb没有删除干净,我的天,自己挖坑自己跳。
[root@VM_235_40_centos yum.repos.d]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@VM_235_40_centos yum.repos.d]# rpm -ev mariadb-libs-5.5.52-1.el7.x86_64 --nodeps
Preparing packages...
mariadb-libs-1:5.5.52-1.el7.x86_64
- 1
- 2
- 3
- 4
- 5
再来一遍
[root@VM_235_40_centos yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el6 will be installed
......
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================
Package Arch Version Repository Size
==================================================================================================
Installing:
mysql-community-server x86_64 5.7.17-1.el6 mysql57-community 151 M
Installing for dependencies:
mysql-community-client x86_64 5.7.17-1.el6 mysql57-community 23 M
mysql-community-common x86_64 5.7.17-1.el6 mysql57-community 328 k
mysql-community-libs x86_64 5.7.17-1.el6 mysql57-community 2.1 M
numactl-libs x86_64 2.0.9-6.el7_2 os 29 k
Transaction Summary
==================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 177 M
Installed size: 879 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-common-5.7.17- FAILED
http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.17-1.el6.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
mysql-community-client-5.7.17- FAILED
http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.17-1.el6.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
......
Error downloading packages:
mysql-community-server-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
mysql-community-common-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
mysql-community-libs-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
mysql-community-client-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
尼玛,又出错了,Linux上装软件就是蛋疼,404错误请求失败,这又是什么鬼,我前前后后有把安装过程捋了一遍,还是出错,不行,默默地问度娘去。
这里有篇博客,里面说是yum缓存的问题,好吧清楚缓存。
[root@VM_235_40_centos yum.repos.d]# cd /var/cache
[root@VM_235_40_centos cache]# ls
httpd ldconfig man yum
[root@VM_235_40_centos cache]# cd yum
[root@VM_235_40_centos yum]# ls
x86_64
[root@VM_235_40_centos yum]# rm -drf x86_64
[root@VM_235_40_centos yum]# ls
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
重新再来
[root@VM_235_40_centos yum]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql57-community | 2.5 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/10): epel/7/x86_64/group_gz | 170 kB 00:00:00
(2/10): epel/7/x86_64/updateinfo | 762 kB 00:00:00
(3/10): epel/7/x86_64/primary_db | 4.6 MB 00:00:00
(4/10): extras/7/x86_64/primary_db | 139 kB 00:00:00
(5/10): os/7/x86_64/group_gz | 155 kB 00:00:00
(6/10): updates/7/x86_64/primary_db | 3.8 MB 00:00:00
(7/10): os/7/x86_64/primary_db | 5.6 MB 00:00:00
(8/10): mysql-connectors-community/x86_64/primary_db | 13 kB 00:00:00
(9/10): mysql-tools-community/x86_64/primary_db | 32 kB 00:00:00
(10/10): mysql57-community/x86_64/primary_db | 96 kB 00:00:01
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el7 will be installed
......
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================
Package Arch Version Repository Size
==================================================================================================
Installing:
mysql-community-server x86_64 5.7.17-1.el7 mysql57-community 162 M
Installing for dependencies:
mysql-community-client x86_64 5.7.17-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.17-1.el7 mysql57-community 271 k
mysql-community-libs x86_64 5.7.17-1.el7 mysql57-community 2.1 M
numactl-libs x86_64 2.0.9-6.el7_2 os 29 k
Transaction Summary
==================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 188 M
Installed size: 847 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.17-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.17-1.el7.x86_64.rpm | 271 kB 00:00:03
(2/5): mysql-community-libs-5.7.17-1.el7.x86_64.rpm | 2.1 MB 00:00:52
(3/5): numactl-libs-2.0.9-6.el7_2.x86_64.rpm | 29 kB 00:00:00
(4/5): mysql-community-client-5.7. 6% [=- ] 101 kB/s | 12 MB 00:29:51 ETA
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
没问题了,只是我这服务器带宽不行,默默地等吧。
Installed:
mysql-community-server.x86_64 0:5.7.17-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.17-1.el7
mysql-community-common.x86_64 0:5.7.17-1.el7
mysql-community-libs.x86_64 0:5.7.17-1.el7
numactl-libs.x86_64 0:2.0.9-6.el7_2
Complete!
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
此处应有掌声
4. 最后一步了,启动服务
官网的安装指南使用service mysqld start
,CentOS7改用systemctl命令启动服务了,使用service命令会默认转向调用systemctl命令的。
附加步骤,修改MySQL密码,修改MySQL默认端口
MySQL5.7之前的版本如果按照这种方式安装后,默认是没有密码的。对于MySQL5.7 有点特殊,下面是官网描述MySQL5.7的安装过程:
- 服务初始化
- 在data文件夹生成SSL证书和密钥
- 安装validate_password 插件并生效
- 创建数据库超级管理员’root@localhost’,并为他生成密码
也就是说MySQL5.7后生成了为root超级管理员生成了一个密码,这个密码在/var/log/mysqld.log
文件中
shell> sudo grep 'temporary password' /var/log/mysqld.log
- 1
上面红圈部分就是生成的随即密码,然后进入mysql修改密码,当然修改密码的方式有很多种,这个可以自行百度。
修改端口
mysql的配置文件在/etc/my.cnf
修改端口只需要添加一行port=[修改的端口号]
,记得重启服务
搞了两节课终于TM折腾完了
命令总结
yum: Yellow dog Updater, Modified, 解决rpm包依赖的软件安装工具,可以在/etc/yum.config文件中进行yum的配置,yum数据源默认放在/etc/yum.repos.d/文件夹下。可以认为是rpm的加强版。
rpm: RedHat Package Manager,软件安装包的管理器,可以用来安装或删除软件。
wget: World Wide Web Get,wget是一个从网络上自动下载文件的自由工具,支持HTTP、HTTPS、FTP常见协议。
uname: Unix Name,显示主机操作系统名称。