1. 程式人生 > >阿里雲Centos7使用yum安裝MySQL5.6

阿里雲Centos7使用yum安裝MySQL5.6

我要在自己的阿里雲伺服器上搭建hadoop+hive+mysql+tomcat環境,以下為mysql的安裝記錄

→_→大家都知道,centos自帶的repo是不會自動更新每個軟體的最新版本,所以無法通過yum方式安裝MySQL的高階版本。所以,即使我使勁用yum -y install mysql mysql-server mysql-devel,也是沒有人會鳥我的。  所以,正確的安裝mysql5姿勢是要先安裝帶有可用的mysql5系列社群版資源的rpm包

[[email protected] ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
獲取http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
準備中...                          ################################# [100%]
正在升級/安裝...
   1:mysql-community-release-el7-5    ################################# [100%]

這個時候檢視當前可用的mysql安裝資源:

[[email protected] ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  17
mysql-tools-community/x86_64      MySQL Tools Community                       31
mysql56-community/x86_64          MySQL 5.6 Community Server                 199

一般來說,只要安裝mysql-server跟mysql-client  這個時候我們可以直接使用yum的方式安裝MySQL了

[[email protected] ~]# yum -y install mysql-community-server
已載入外掛:langpacks
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 mysql-community-server.x86_64.0.5.6.28-2.el7 將被 安裝
--> 正在處理依賴關係 mysql-community-common(x86-64) = 5.6.28-2.el7,它被軟體包 mysql-community-server-5.6.28-2.el7.x86_64 需要
--> 正在處理依賴關係 mysql-community-client(x86-64) = 5.6.28-2.el7,它被軟體包 mysql-community-server-5.6.28-2.el7.x86_64 需要
--> 正在處理依賴關係 perl(DBI),它被軟體包 mysql-community-server-5.6.28-2.el7.x86_64 需要
--> 正在檢查事務
---> 軟體包 mysql-community-client.x86_64.0.5.6.28-2.el7 將被 安裝
--> 正在處理依賴關係 mysql-community-libs(x86-64) = 5.6.28-2.el7,它被軟體包 mysql-community-client-5.6.28-2.el7.x86_64 需要
---> 軟體包 mysql-community-common.x86_64.0.5.6.28-2.el7 將被 安裝
---> 軟體包 perl-DBI.x86_64.0.1.627-4.el7 將被 安裝
--> 正在處理依賴關係 perl(RPC::PlServer) >= 0.2001,它被軟體包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在處理依賴關係 perl(RPC::PlClient) >= 0.2000,它被軟體包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在檢查事務
---> 軟體包 mariadb-libs.x86_64.1.5.5.40-1.el7_0 將被 取代
---> 軟體包 mysql-community-libs.x86_64.0.5.6.28-2.el7 將被 捨棄
---> 軟體包 perl-PlRPC.noarch.0.0.2020-14.el7 將被 安裝
--> 正在處理依賴關係 perl(Net::Daemon) >= 0.13,它被軟體包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在處理依賴關係 perl(Net::Daemon::Test),它被軟體包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在處理依賴關係 perl(Net::Daemon::Log),它被軟體包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在處理依賴關係 perl(Compress::Zlib),它被軟體包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在檢查事務
---> 軟體包 perl-IO-Compress.noarch.0.2.061-2.el7 將被 安裝
--> 正在處理依賴關係 perl(Compress::Raw::Zlib) >= 2.061,它被軟體包 perl-IO-Compress-2.061-2.el7.noarch 需要
--> 正在處理依賴關係 perl(Compress::Raw::Bzip2) >= 2.061,它被軟體包 perl-IO-Compress-2.061-2.el7.noarch 需要
---> 軟體包 perl-Net-Daemon.noarch.0.0.48-5.el7 將被 安裝
--> 正在檢查事務
---> 軟體包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 將被 安裝
---> 軟體包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

==============================================================================================
 Package                       架構         版本                源                       大小
==============================================================================================
正在安裝:
 mysql-community-libs          x86_64       5.6.28-2.el7        mysql56-community       2.0 M
      替換  mariadb-libs.x86_64 1:5.5.40-1.el7_0
 mysql-community-server        x86_64       5.6.28-2.el7        mysql56-community        58 M
為依賴而安裝:
 mysql-community-client        x86_64       5.6.28-2.el7        mysql56-community        19 M
 mysql-community-common        x86_64       5.6.28-2.el7        mysql56-community       256 k
 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-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

事務概要
==============================================================================================
安裝  2 軟體包 (+8 依賴軟體包)

總下載量:80 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.28-2.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 金鑰 ID 5072e1f5: NOKEY
mysql-community-common-5.6.28-2.el7.x86_64.rpm 的公鑰尚未安裝
(1/10): mysql-community-common-5.6.28-2.el7.x86_64.rpm                 | 256 kB  00:00:14     
(2/10): mysql-community-libs-5.6.28-2.el7.x86_64.rpm                   | 2.0 MB  00:02:57     
(3/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                  |  57 kB  00:00:00     
(4/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                 |  32 kB  00:00:00     
(5/10): perl-IO-Compress-2.061-2.el7.noarch.rpm                        | 260 kB  00:00:00     
(6/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm                          |  51 kB  00:00:00     
(7/10): perl-PlRPC-0.2020-14.el7.noarch.rpm  
(8/10): perl-DBI-1.627-4.el7.x86_64.rpm                                | 802 kB  00:00:00     
(9/10): mysql-community-server-5.6.28-2.el7.x86_64.rpm                 |  58 MB  00:54:45     
(10/10): mysql-community-client-5.6.28-2.el7.x86_64.rpm                |  19 MB  00:20:42     
總計                                                           13 kB/s |  80 MB  01:45:50     
從 file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 檢索金鑰
匯入 GPG key 0x5072E1F5:
 使用者ID     : "MySQL Release Engineering <
[email protected]
>" 指紋 : 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 Running transaction check Running transaction test Transaction test succeeded Running transaction 警告:RPM 資料庫已被非 yum 程式修改。 正在安裝 : mysql-community-common-5.6.28-2.el7.x86_64 1/11 正在安裝 : mysql-community-libs-5.6.28-2.el7.x86_64 2/11 正在安裝 : mysql-community-client-5.6.28-2.el7.x86_64 3/11 正在安裝 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 4/11 正在安裝 : perl-Net-Daemon-0.48-5.el7.noarch 5/11 正在安裝 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 6/11 正在安裝 : perl-IO-Compress-2.061-2.el7.noarch 7/11 正在安裝 : perl-PlRPC-0.2020-14.el7.noarch 8/11 正在安裝 : perl-DBI-1.627-4.el7.x86_64 9/11 正在安裝 : mysql-community-server-5.6.28-2.el7.x86_64 10/11 正在刪除 : 1:mariadb-libs-5.5.40-1.el7_0.x86_64 11/11 驗證中 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/11 驗證中 : perl-Net-Daemon-0.48-5.el7.noarch 2/11 驗證中 : mysql-community-common-5.6.28-2.el7.x86_64 3/11 驗證中 : perl-IO-Compress-2.061-2.el7.noarch 4/11 驗證中 : mysql-community-libs-5.6.28-2.el7.x86_64 5/11 驗證中 : mysql-community-client-5.6.28-2.el7.x86_64 6/11 驗證中 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 7/11 驗證中 : perl-DBI-1.627-4.el7.x86_64 8/11 驗證中 : mysql-community-server-5.6.28-2.el7.x86_64 9/11 驗證中 : perl-PlRPC-0.2020-14.el7.noarch 10/11 驗證中 : 1:mariadb-libs-5.5.40-1.el7_0.x86_64 11/11 已安裝: mysql-community-libs.x86_64 0:5.6.28-2.el7 mysql-community-server.x86_64 0:5.6.28-2.el7 作為依賴被安裝: mysql-community-client.x86_64 0:5.6.28-2.el7 mysql-community-common.x86_64 0:5.6.28-2.el7 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-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 替代: mariadb-libs.x86_64 1:5.5.40-1.el7_0 完畢!

安裝完的配置

加入開機啟動

[[email protected] ~]# systemctl enable mysqld

啟動mysql服務程序

[[email protected] ~]# systemctl start mysqld

重置密碼

[[email protected] ~]# 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] n            [禁止root遠端登入]
 ... skipping.

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...

示例:新建測試資料庫

//登入MYSQL(有ROOT許可權)。這裡我以ROOT身份登入
[[email protected] ~]# mysql -u root -p//修改訪問許可權,讓其他計算機也能訪問GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
//首先為使用者建立一個數據庫hivemeta
mysql  > create database test;
mysql  > use test
//授權hdp使用者擁有hivemeta資料庫的所有許可權。
mysql  > grant all privileges on *.* to [email protected]"%" identified by "hdp" with grant option;
//刷新系統許可權表
mysql  > flush privileges;
mysql  > use test;
//mysql/hive字符集問題
mysql  > alter database test character set latin1;測試連線......