前言:rpm方式或者這種yum安裝時比較簡單的方式,但是不推薦,但是確實很着急的話,可以采用這種安裝
這種方式不利於后續對mysql的管理,如果是多實例或者是復雜的一些架構的話,還是推薦利用源碼包編譯方式進行安裝。
這篇文章看似簡單,但是我修正了多次,所以后續還會繼續補充和糾正,盡量不能給其他人造成錯誤的引導。
首先查看操作系統版本,操作系統采用的是centos(非debian等操作系統),其他操作系統命令會不一樣,包括配置文件以及默認安裝路徑等,所以初步了解操作系統很必要
安裝之前需要檢查一下機器上是否有mysql,同時要對軟件本身要所有了解,包括該軟件依賴的相關包或系統版本過低都可能造成安裝當中的問題. 比如:你安裝k8s 二進制版本的時候,如果系統是centos 6 基本你的docker就安裝不上,或者遇到各種各樣的令人頭痛的問題,后續維護成本也會很大,所以最起碼安裝docker要在centos7.* 以上。
[root@fp-web-118 local]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@fp-web-118 local]# rpm -qa | grep mysql
執行安裝命令
[root@fp-web-118 local]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package mysql-community-server available.
Error: Nothing to do
注意:rpm方式是 rpm -ivh MySQL-server-5.0.9-0.i386.rpm, 他們之間有區別
發現安裝提示錯誤什么也沒干,查看yum源,yum源一般在/etc/yum.repos.d中(源的后綴是.repo)
[root@fp-web-118 local]# ll /etc/yum.repos.d/
total 36
-rw-r--r-- 1 root root 2523 Feb 15 2019 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo
-rw-r--r-- 1 root root 664 Feb 15 2019 epel.repo
-rw-r--r-- 1 root root 401 Feb 15 2016 zabbix.repo
在CentOS 6.x版本中的確存在MySQL的安裝包,但CentOS 7.x之后版本,MySQL的yum源被踢出,取而代之的是MariaDB源 。 但是我們也沒有看到,可能系統被改動過,因為用的是雲服務。
所以最好你也看下 rpm -qa | grep MariaDB
安裝sz和rz命令(注:由於沒有mysql.repo,需要上傳mysql.repo yum源)
[root@fp-web-118 yum.repos.d]# yum install lrzsz
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================
Package Arch Version Repository Size
====================================================================================
Installing:
lrzsz x86_64 0.12.20-36.el7 base 78 k
Transaction Summary
=====================================================================================
Install 1 Package
Total download size: 78 k
Installed size: 181 k
Is this ok [y/d/N]: ys^Hes
Is this ok [y/d/N]: yes
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm | 78 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lrzsz-0.12.20-36.el7.x86_64 1/1
Verifying : lrzsz-0.12.20-36.el7.x86_64 1/1
Installed:
lrzsz.x86_64 0:0.12.20-36.el7
Complete!
利用rz 命令上傳yum 源(這個yum源mysql-community.repo是從其他機器上copy過來的) , 看看上傳以后的列表
[root@fp-web-118 yum.repos.d]# ll
total 40
-rw-r--r-- 1 root root 2523 Feb 15 2019 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo
-rw-r--r-- 1 root root 664 Feb 15 2019 epel.repo
-rw-r--r-- 1 root root 1862 May 16 2018 mysql-community.repo
-rw-r--r-- 1 root root 401 Feb 15 2016 zabbix.repo
我們也可以利用其他方式,安裝mysql repo源
#下載官方的MySQLyum源,在阿里源中可下載對應的源。
測試,我備份了我的mysql repo源(這塊是我在后補這篇文檔的時候做了一個測試,就是repo源的安裝,不過發現阿里這些源有時候也找不到有些包,比如k8s的基礎鏡像包)
[root@fp-web-118 yum.repos.d]# ll
total 40
-rw-r--r-- 1 root root 2523 Feb 15 2019 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo
-rw-r--r-- 1 root root 664 Feb 15 2019 epel.repo
-rw-r--r-- 1 root root 1862 Jan 30 20:11 mysql-community.repo
-rw-r--r-- 1 root root 401 Feb 15 2016 zabbix.repo
[root@fp-web-118 yum.repos.d]# cp mysql-community.repo mysql-community.repo.bak
[root@fp-web-118 src]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
--2022-02-01 16:56:59-- https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm [following]
--2022-02-01 16:56:59-- https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.58.112.230
Connecting to repo.mysql.com (repo.mysql.com)|23.58.112.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25820 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-1.noarch.rpm’
100%[=====================================================================================================================================================>] 25,820 129KB/s in 0.2s
2022-02-01 16:57:01 (129 KB/s) - ‘mysql80-community-release-el7-1.noarch.rpm’ saved [25820/25820]
##下載到的/usr/local/src下
[root@fp-web-118 src]# ll | grep mysql
-rw-r--r-- 1 root root 25820 Apr 18 2018 mysql80-community-release-el7-1.noarch.rpm
[root@fp-web-118 src]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
warning: mysql80-community-release-el7-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-1 ################################# [100%]
warning: /etc/yum.repos.d/mysql-community.repo created as /etc/yum.repos.d/mysql-community.repo.rpmnew
#安裝剛剛從官方下載的yum源,會在"/etc/yum.repos.d/"下生成相應的mysql社區版的repo配置文件。
warning: mysql80-community-release-el7-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-1 ################################# [100%]
[root@fp-web-118 src]# ll /etc/yum.repos.d/ | grep mysql
-rw-r--r-- 1 root root 1862 Jan 30 20:11 mysql-community.repo
-rw-r--r-- 1 root root 1862 Feb 1 16:56 mysql-community.repo.bak ###這個是我之前做的備份,這篇文章是用的這個repo源
-rw-r--r-- 1 root root 1864 Feb 22 2018 mysql-community.repo.rpmnew
-rw-r--r-- 1 root root 1885 Feb 22 2018 mysql-community-source.repo
重新執行安裝mysql rpm命令
[root@fp-web-118 yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql56-community | 2.6 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 76 kB 00:00:00
(2/3): mysql56-community/x86_64/primary_db | 338 kB 00:00:01
(3/3): mysql-tools-community/x86_64/primary_db | 73 kB 00:00:01
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.51-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.51-2.el6 for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.51-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.51-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.51-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.51-2.el6 will be installed
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===========================================================================
Installing:
mysql-community-server x86_64 5.6.51-2.el6 mysql56-community 62 M
Installing for dependencies:
mysql-community-client x86_64 5.6.51-2.el6 mysql56-community 20 M
mysql-community-common x86_64 5.6.51-2.el6 mysql56-community 340 k
mysql-community-libs x86_64 5.6.51-2.el6 mysql56-community 2.2 M
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-Data-Dumper x86_64 2.145-3.el7 base 47 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Transaction Summary
================================================================================
Install 1 Package (+10 Dependent packages)
Total download size: 86 M
Installed size: 355 M
Is this ok [y/d/N]: yes
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.51-2.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY47 kB/s | 280 kB 00:09:58 ETA
Public key for mysql-community-common-5.6.51-2.el6.x86_64.rpm is not installed
(1/11): mysql-community-common-5.6.51-2.el6.x86_64.rpm | 340 kB 00:00:01
(2/11): mysql-community-libs-5.6.51-2.el6.x86_64.rpm | 2.2 MB 00:00:02
(3/11): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00
(4/11): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00
(5/11): perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00:00
(6/11): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00
(7/11): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00
(8/11): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00
(9/11): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00
(10/11): mysql-community-client-5.6.51-2.el6.x86_64.rpm | 20 MB 00:00:19
(11/11): mysql-community-server-5.6.51-2.el6.x86_64.rpm | 62 MB 00:00:36
------------------------------------------------------------------------------------------
Total 2.1 MB/s | 86 MB 00:00:40
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"
解決這個問題
gpg key retrieval failed 意思是在/etc/pki/rpm-gpg/中找不到RPM-GPG-KEY-mysql
第一種方案,設置gpgcheck為0,就是不需要檢查gpgkey。
# 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
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
第二種方案,指定外網gpgkey的值
# 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
gpgcheck=0 gpgkey=http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
第三種方案,下載gpgkey
//下載RPM-GPG-KEY-mysql
wget http://repo.mysql.com/RPM-GPG-KEY-mysql -O /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
//MySQL中gpgkey指定路徑
# 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
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解決出錯問題,我們再看一下 yum源文件 mysql-community.repo
[root@fp-web-118 yum.repos.d]# vi mysql-community.repo
# 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/6/$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/6/$basearch/
enabled=1
gpgcheck=1 ##這里修改為0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# 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/6/$basearch/
enabled=0
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/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/6/$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/6/$basearch/
enabled=1
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/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
保存,退出
重新執行 mysql安裝命令
[root@fp-web-118 yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql56-community | 2.6 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.51-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.51-2.el6 for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.6.10 for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-server-5.6.51-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.51-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.6.10 for package: mysql-community-client-5.6.51-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.51-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.51-2.el6 will be installed
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================
Package Arch Version Repository Size
========================================================
Installing:
mysql-community-server x86_64 5.6.51-2.el6 mysql56-community 62 M
Installing for dependencies:
mysql-community-client x86_64 5.6.51-2.el6 mysql56-community 20 M
mysql-community-common x86_64 5.6.51-2.el6 mysql56-community 340 k
mysql-community-libs x86_64 5.6.51-2.el6 mysql56-community 2.2 M
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-Data-Dumper x86_64 2.145-3.el7 base 47 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Transaction Summary
=======================================================
Install 1 Package (+10 Dependent packages)
Total size: 86 M
Installed size: 355 M
Is this ok [y/d/N]: yes
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-5.6.51-2.el6.x86_64 1/11
Installing : perl-Data-Dumper-2.145-3.el7.x86_64 2/11
Installing : mysql-community-libs-5.6.51-2.el6.x86_64 3/11
Installing : mysql-community-client-5.6.51-2.el6.x86_64 4/11
Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 5/11
Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 6/11
Installing : perl-IO-Compress-2.061-2.el7.noarch 7/11
Installing : perl-Net-Daemon-0.48-5.el7.noarch 8/11
Installing : perl-PlRPC-0.2020-14.el7.noarch 9/11
Installing : perl-DBI-1.627-4.el7.x86_64 10/11
Installing : mysql-community-server-5.6.51-2.el6.x86_64 11/11
Verifying : perl-Net-Daemon-0.48-5.el7.noarch 1/11
Verifying : perl-Data-Dumper-2.145-3.el7.x86_64 2/11
Verifying : mysql-community-server-5.6.51-2.el6.x86_64 3/11
Verifying : mysql-community-common-5.6.51-2.el6.x86_64 4/11
Verifying : perl-IO-Compress-2.061-2.el7.noarch 5/11
Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 6/11
Verifying : mysql-community-libs-5.6.51-2.el6.x86_64 7/11
Verifying : mysql-community-client-5.6.51-2.el6.x86_64 8/11
Verifying : perl-DBI-1.627-4.el7.x86_64 9/11
Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 10/11
Verifying : perl-PlRPC-0.2020-14.el7.noarch 11/11
Installed:
mysql-community-server.x86_64 0:5.6.51-2.el6
Dependency Installed:
mysql-community-client.x86_64 0:5.6.51-2.el6 mysql-community-common.x86_64 0:5.6.51-2.el6 mysql-community-libs.x86_64 0:5.6.51-2.el6 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
我們通過配置文件可以看到默認安裝的路徑是 /var/lib/mysql
查看 /etc/my.cnf , 默認安裝的,我什么也沒有動
[root@fp-web-118 yum.repos.d]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
啟動和關閉mysql如下
啟動方式一:
[root@fp-web-118 yum.repos.d]# /etc/init.d/mysqld start
Starting mysqld (via systemctl): [ OK ]
注: /etc/init.d/mysqld 實際也是shell文件,它和/usr/sbin/mysqld 是不同的,后者實際是二進制文件。
我們可以通過 /sbin/chkconfig – add mysql 命令加入到添加到你系統的啟動服務組里面去 service mysql start 方式啟動
啟動方式二(linux啟動MySQL的命令,相關的mysql管理命令安裝在/usr/bin下可以找到:)
[root@fp-web-118 yum.repos.d]# mysqld_safe &
關閉方式一:
[root@fp-web-118 yum.repos.d]#/etc/init.d/mysqld stop
關閉方式二 (相關的mysql管理命令安裝在/usr/bin下可以找到)
[root@fp-web-118 bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@fp-web-118 bin]# mysqladmin -uroot -p shutdown
查看進程
[root@fp-web-118 yum.repos.d]# ps -efww| grep mysql
root 77993 1 0 20:14 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 78198 77993 0 20:14 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
/usr/sbin/mysqld是二進制文件,mysqld_safe實際是一個shell文件
所以有必要也要看看mysqld_safe和mysqld的區別。
東西比較分散:
/usr, /var/lib/mysql,/usr/lib64/mysql,/var/log/ ,/var/run
所以這種方式也能看出不利於管理。
登錄mysql
[root@fp-web-118 yum.repos.d]# mysql -h localhost -u root -p
Enter password: ####剛開始安裝之后,密碼默認為空
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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> select version();
+-----------+
| version() |
+-----------+
| 5.6.51 |
+-----------+
1 row in set (0.00 sec)
以下為后補的內容
這里注意,我多次啟動、關閉的時候沒有注意密碼問題,當我再次登錄提示我密碼不對,所以我不得不重新執行授權表,當然也有別的辦法,因為是新的mysql,我直接用下面的重新設置
[root@fp-web-118 yum.repos.d]# mysql_install_db --datadir=/var/lib/mysql (這里注意沒有空格即 --datadir = /var/lib/mysql 這樣會出錯)
Installing MySQL system tables...2022-02-01 20:38:29 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-02-01 20:38:29 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-02-01 20:38:29 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 75620 ...
2022-02-01 20:38:29 75620 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-02-01 20:38:29 75620 [Note] InnoDB: The InnoDB memory heap is disabled
2022-02-01 20:38:29 75620 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
..... ##其他部分我刪除掉了,留下提示
/usr/bin/mysqladmin -u root password 'jinzs'
/usr/bin/mysqladmin -u root -h fp-web-118 password 'jinzs'
你可以運行
/usr/bin/mysql_secure_installation
他會給你一些選項去刪除test數據庫或者是匿名的用戶,通過默認方式安裝得時候
cd /usr ; /usr/bin/mysqld_safe &
你可以測試你的mysql,用這個腳本 mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
WARNING: 默認使用的是/etc/my.cnf,如果不想使用這個默認文件你也可以通過 --defaults-file 這個參數進行設置mysql,在開始命令里面
現在就可以登錄了
[root@fp-web-118 bin]# mysql -u root -h fp-web-118 -pjinzs
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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.6.51 ,當然想刪除也很簡單
首先查看一下系統內安裝的mysql信息
[root@fp-web-118 yum.repos.d]# rpm -qa | grep mysql
mysql-community-common-5.6.51-2.el6.x86_64 組件
mysql-community-client-5.6.51-2.el6.x86_64 客戶端
mysql-community-libs-5.6.51-2.el6.x86_64 依賴庫
mysql-community-server-5.6.51-2.el6.x86_64 服務端
刪除利用yum安裝的mysql
yum -y remove mysql-community-common-5.6.51-2.el6.x86_64
我們在看看rpm方式安裝之后,安裝的位置情況
1、數據庫目錄
/var/lib/mysql/
2、/usr/share/mysql(mysql.server命令及配置文件)
[root@fp-web-118 mysql]# ll /usr/share/mysql | grep mysql
-rw-r--r-- 1 root root 844 Jan 5 2021 mysql-log-rotate
-rw-r--r-- 1 root root 2121 Jan 5 2021 mysql_security_commands.sql
-rw-r--r-- 1 root root 3972 Jan 5 2021 mysql_system_tables_data.sql
-rw-r--r-- 1 root root 93667 Jan 5 2021 mysql_system_tables.sql
-rw-r--r-- 1 root root 10834 Jan 5 2021 mysql_test_data_timezone.sql
3、相關命令 /usr/bin
[root@fp-web-118 bin]# ll | grep mysql
-rwxr-xr-x 1 root root 1956 Jan 5 2021 msql2mysql
-rwxr-xr-x 1 root root 9373167 Jan 5 2021 mysql
-rwxr-xr-x 1 root root 112528 Jan 5 2021 mysqlaccess
-rw-r--r-- 1 root root 1702 Jan 5 2021 mysqlaccess.conf
-rwxr-xr-x 1 root root 8339464 Jan 5 2021 mysqladmin
-rwxr-xr-x 1 root root 9183394 Jan 5 2021 mysqlbinlog
-rwxr-xr-x 1 root root 11602 Jan 5 2021 mysqlbug
-rwxr-xr-x 1 root root 8323384 Jan 5 2021 mysqlcheck
-rwxr-xr-x 1 root root 8411442 Jan 5 2021 mysql_config_editor
-rwxr-xr-x 1 root root 4716 Jan 5 2021 mysql_convert_table_format
-rwxr-xr-x 1 root root 26919 Jan 5 2021 mysqld_multi
-rwxr-xr-x 1 root root 26630 Jan 5 2021 mysqld_safe
-rwxr-xr-x 1 root root 8608337 Jan 5 2021 mysqldump
-rwxr-xr-x 1 root root 7825 Jan 5 2021 mysqldumpslow
-rwxr-xr-x 1 root root 3791 Jan 5 2021 mysql_find_rows
-rwxr-xr-x 1 root root 1732 Jan 5 2021 mysql_fix_extensions
-rwxr-xr-x 1 root root 35339 Jan 5 2021 mysqlhotcopy
-rwxr-xr-x 1 root root 8345555 Jan 5 2021 mysqlimport
-rwxr-xr-x 1 root root 35067 Jan 5 2021 mysql_install_db
-rwxr-xr-x 1 root root 6796176 Jan 5 2021 mysql_plugin
-rwxr-xr-x 1 root root 10525 Jan 5 2021 mysql_secure_installation
-rwxr-xr-x 1 root root 8316240 Jan 5 2021 mysqlshow
-rwxr-xr-x 1 root root 8404798 Jan 5 2021 mysqlslap
-rwxr-xr-x 1 root root 9119043 Jan 5 2021 mysqltest
-rwxr-xr-x 1 root root 4487695 Jan 5 2021 mysql_tzinfo_to_sql
-rwxr-xr-x 1 root root 8488273 Jan 5 2021 mysql_upgrade
-rwxr-xr-x 1 root root 6730715 Jan 5 2021 mysql_waitpid
-rwxr-xr-x 1 root root 4359 Jan 5 2021 mysql_zap
4、相關啟動腳本
/etc/rc.d/init.d/(啟動腳本文件mysql的目錄)
5、配置文件所在位置 /etc/my.cnf
data目錄重新設置(對yum方式安裝的mysql進行調整,因為可能你分區時/var/並沒有多大的空間,所以需要進行轉移)
假如要把核心的數據目錄移到其他目錄 例如 /usr/local/mysql/data下需要進行下面幾步:
1、把MySQL服務進程停掉:
mysqladmin -u root -p shutdown 或 service mysql stop 或 /etc/rc.d/init.d/mysql stop
這里可以把mysql添加至服務列表:
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start/stop/restart等
2、/usr/local/mysql目錄下建立data目錄
cd /usr/local/mysql
mkdir data
3、把/var/lib/mysql整個目錄移到/usr/local/mysql/data (這個位置實際只是想集中管理而已,我們也可以放在其他位置,我這里想在/usr/local/mysql下集中做管理)
mv /var/lib/mysql /usr/local/mysql/data/
這樣就把MySQL的數據文件移動到了/usr/local/mysql/data/mysql下
4、找到my.cnf配置文件
如果/etc/目錄下沒有my.cnf配置文件,命令如下:
[mysqld]
datadir=/usr/local/mysql/data ##注意更改data目錄的所屬 chown -R mysql:mysql /usr/local/mysql