CentOS7下yum方式安裝mysql5.6


在Centos7中用MariaDB代替了mysql數據庫。所以在新安裝MySQL前必須做好對系統的清理工作。

一.清理CentOS7下的MariaDB。

[root@localhost ~]#rpm -qa | gremp mariadb

        [root@localhost ~]# rpm -e --nodeps mariadb.x86_64 1:5.5.41-2.el7_0

二.下載MySQL的yum包

Linux系統自帶的repo是不會自動更新每個軟件的最新版本(基本都是比較靠后的穩定版),所以無法通過yum方式安裝MySQL的高級版本。所以我們需要先安裝帶有當前可用的mysql5系列社區版資源的rpm包(確保電腦聯網)。

        [root@localhost ~]#wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

查看當前可用的mysql安裝資源

       [root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64  MySQL Connectors Community   21
mysql-tools-community/x86_64       MySQL Tools Community        33
mysql56-community/x86_64           MySQL 5.6 Community Server  214

安裝mysql

[root@localhost ~]#yum install mysql-community-server

已加載插件:fastestmirror, langpacks

base                                      | 3.6 kB     00:00    

extras                                    | 3.4 kB     00:00    

mysql-connectors-community                | 2.5 kB     00:00    

mysql-tools-community                     | 2.5 kB     00:00    

mysql56-community                         | 2.5 kB     00:00    

updates                                   | 3.4 kB     00:00    

(1/5): extras/7/x86_64/primary_db         | 117 kB   00:00    

(2/5): mysql-connectors-community/x86_64/primary_db | 9.8 kB   00:00    

(3/5): mysql-tools-community/x86_64/primary_db   |  25 kB   00:01    

(4/5): mysql56-community/x86_64/primary_db       | 115 kB   00:01    

(5/5): updates/7/x86_64/primary_db               | 3.9 MB   00:01    

Determining fastest mirrors

 * base: mirrors.pubyun.com

 * extras: mirrors.pubyun.com

 * updates: mirrors.pubyun.com

正在解決依賴關系

--> 正在檢查事務

---> 軟件包 mysql-community-server.x86_64.0.5.6.29-2.el7 將被 安裝

--> 正在處理依賴關系 mysql-community-common(x86-64) = 5.6.29-2.el7,它被軟件包 mysql-community-server-5.6.29-2.el7.x86_64 需要

--> 正在處理依賴關系 mysql-community-client(x86-64) = 5.6.29-2.el7,它被軟件包 mysql-community-server-5.6.29-2.el7.x86_64 需要

--> 正在檢查事務

---> 軟件包 mysql-community-client.x86_64.0.5.6.29-2.el7 將被 安裝

--> 正在處理依賴關系 mysql-community-libs(x86-64) = 5.6.29-2.el7,它被軟件包 mysql-community-client-5.6.29-2.el7.x86_64 需要

---> 軟件包 mysql-community-common.x86_64.0.5.6.29-2.el7 將被 安裝

--> 正在檢查事務

---> 軟件包 mysql-community-libs.x86_64.0.5.6.29-2.el7 將被 安裝

--> 解決依賴關系完成

 

依賴關系解決

 

=================================================================

 Package        架構      版本           源                  大小

=================================================================

正在安裝:

 mysql-community-server    x86_64    5.6.29-2.el7    mysql56-community     58 M

為依賴而安裝:

 mysql-community-client    x86_64    5.6.29-2.el7    mysql56-community     19 M

 mysql-community-common    x86_64    5.6.29-2.el7    mysql56-community    256 k

 mysql-community-libs      x86_64    5.6.29-2.el7    mysql56-community    2.0 M

 

事務概要

=================================================================

安裝  1 軟件包 (+3 依賴軟件包)

 

總下載量:79 M

安裝大小:344 M

Is this ok [y/d/N]: y

Downloading packages:

警告:/var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.29-2.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY

mysql-community-common-5.6.29-2.el7.x86_64.rpm 的公鑰尚未安裝

(1/4): mysql-community-common-5.6.29-2.el7.x86_64.rpm      | 256 kB   00:01    

(2/4): mysql-community-libs-5.6.29-2.el7.x86_64.rpm        | 2.0 MB   00:02    

(3/4): mysql-community-server-5.6.29-2.el7.x86_64.rpm      |  58 MB   00:29    

mysql-community-client-5.6.29- FAILED                                          

http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-client-5.6.29-2.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-client-5.6.29-2.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')

正在嘗試其它鏡像。

(4/4): mysql-community-client-5.6.29-2.el7.x86_64.rpm      |  19 MB   12:12    

-----------------------------------------------------------------

總計                                    105 kB/s |  79 MB  12:51    

從 file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 檢索密鑰

導入 GPG key 0x5072E1F5:

 用戶ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"

 指紋       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5

 軟件包     : mysql-community-release-el7-5.noarch (installed)

 來自       : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

是否繼續?[y/N]:y

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

警告:RPM 數據庫已被非 yum 程序修改。

正在安裝    : mysql-community-common-5.6.29-2.el7.x86_64                  1/4

正在安裝    : mysql-community-libs-5.6.29-2.el7.x86_64                    2/4

正在安裝    : mysql-community-client-5.6.29-2.el7.x86_64                  3/4

正在安裝    : mysql-community-server-5.6.29-2.el7.x86_64                  4/4

warning: /etc/my.cnf created as /etc/my.cnf.rpmnew

驗證中      : mysql-community-common-5.6.29-2.el7.x86_64                  1/4

驗證中      : mysql-community-libs-5.6.29-2.el7.x86_64                    2/4

驗證中      : mysql-community-client-5.6.29-2.el7.x86_64                  3/4

驗證中      : mysql-community-server-5.6.29-2.el7.x86_64                  4/4

 

已安裝:

mysql-community-server.x86_64 0:5.6.29-2.el7                                 

 

作為依賴被安裝:

mysql-community-client.x86_64 0:5.6.29-2.el7                                 

mysql-community-common.x86_64 0:5.6.29-2.el7                                 

mysql-community-libs.x86_64 0:5.6.29-2.el7                                   

 

完畢!

 

三.MySQL安裝完成后,進行相關配置

a)   #######安裝成功后,將其加入開機啟動
systemctl enable mysqld
b) #######啟動mysql服務進程
        systemctl start mysqld
        c) #######配置mysql(設置密碼等)
        mysql_secure_installation
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
 
Set root password? [Y/n] y                  [設置root用戶密碼]
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous users? [Y/n] y                 [刪除匿名用戶]
 ... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n] y       [禁止root遠程登錄]
 ... Success!
 
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
 
Remove test database and access to it? [Y/n] y          [刪除test數據庫]
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y/n] y            [刷新權限]
 ... Success!
 
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
 
Thanks for using MySQL!
 
Cleaning up...

 

四.Yum安裝后mysql的文件所在的位置:

/usr/bin(客戶端程序和腳本)

/usr/sbin(mysql服務器)

/var/lib/mysql/(日志文件和數據庫)

/usr/share/doc/packages(文檔)

/usr/include/mysql(包含(頭)文件)

/usr/lib/mysql(庫文件)

/usr/share/mysql/(錯誤消息和字符集文件)

/usr/share/sql-bench(基准程序)

五.Yum安裝的優缺點

優點:安裝簡單,適合初學者學習使用

缺點:需要單獨下載客戶端和服務器;安裝路徑不靈活,默認路徑不能修改,一台服務器只能安裝一個MySQL


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM