CentOS7下使用Yum安裝MySQL

一. 下載MySQL Yum倉庫的RPM安裝包

1. 訪問http://dev.mysql.com/downloads/repo/yum/ 

選擇對應的RPM包下載,我使用的是CentOS7,所以選擇Linux7的RPM包。若使用命令行方式下載,可在shell下使用wget下載


二. 安裝MySQL RPM安裝包



安裝完成後會將MySQL的Yum倉庫添加到系統的倉庫list中,可以/etc/yum.repos.d目錄下看到新增的兩個文件(mysql-community.repo和mysql-community-source.repo)。
檢查MySQL Yum倉庫是否被添加成功。


三. 安裝MySQL

[root@localhost yum.repos.d]# yum install mysql-community-server
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.yun-idc.com
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.zju.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.17-1.el7 for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be obsoleted
---> Package mysql-community-client.x86_64 0:5.7.17-1.el7 will be obsoleting
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.17-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.17-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: mysql-connector-odbc-5.2.5-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-24.el7_2.1.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: MySQL-python-1.2.5-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: mysql-connector-odbc-5.2.5-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: MySQL-python-1.2.5-1.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.17-1.el7 will be obsoleting
---> Package mysql-connector-odbc.x86_64 0:5.2.5-6.el7 will be updated
---> Package mysql-connector-odbc.x86_64 0:5.3.7-1.el7 will be an update
--> Finished Dependency Resolution


Dependencies Resolved


===========================================================================================================================
 Package                               Arch             Version                 Repository                            Size
===========================================================================================================================
Installing:
 mysql-community-client                x86_64           5.7.17-1.el7            mysql57-community                     24 M
     replacing  mariadb.x86_64 1:5.5.52-1.el7
 mysql-community-libs                  x86_64           5.7.17-1.el7            mysql57-community                    2.1 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-libs-compat           x86_64           5.7.17-1.el7            mysql57-community                    2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-server                x86_64           5.7.17-1.el7            mysql57-community                    162 M
Installing for dependencies:
 mysql-community-common                x86_64           5.7.17-1.el7            mysql57-community                    271 k
Updating for dependencies:
 mysql-connector-odbc                  x86_64           5.3.7-1.el7             mysql-connectors-community           2.7 M


Transaction Summary
===========================================================================================================================
Install  4 Packages (+1 Dependent package)
Upgrade             ( 1 Dependent package)


Total download size: 193 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
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/6): mysql-community-common-5.7.17-1.el7.x86_64.rpm                                               | 271 kB  00:00:02
(2/6): mysql-community-libs-5.7.17-1.el7.x86_64.rpm                                                 | 2.1 MB  00:00:16
(3/6): mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm                                          | 2.0 MB  00:00:17
Public key for mysql-connector-odbc-5.3.7-1.el7.x86_64.rpm is not installed              ] 339 kB/s |  16 MB  00:08:51 ETA
(4/6): mysql-connector-odbc-5.3.7-1.el7.x86_64.rpm                                                  | 2.7 MB  00:00:20
(5/6): mysql-community-client-5.7.17-1.el7.x86_64.rpm                                               |  24 MB  00:03:45
(6/6): mysql-community-server-5.7.17-1.el7.x86_64.rpm                                               | 162 MB  00:27:18
---------------------------------------------------------------------------------------------------------------------------
Total                                                                                      118 kB/s | 193 MB  00:27:55
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.17-1.el7.x86_64                                                              1/9
  Installing : mysql-community-libs-5.7.17-1.el7.x86_64                                                                2/9
  Installing : mysql-community-client-5.7.17-1.el7.x86_64                                                              3/9
  Installing : mysql-community-server-5.7.17-1.el7.x86_64 [##################################                        ] 4/9[root@localhost yum.repos.d]# yum install mysql-community-server
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.yun-idc.com
 * extras: mirrors.zju.edu.cn
  Installing : mysql-community-server-5.7.17-1.el7.x86_64                                                              4/9
  Installing : mysql-community-libs-compat-5.7.17-1.el7.x86_64                                                         5/9
  Updating   : mysql-connector-odbc-5.3.7-1.el7.x86_64                                                                 6/9
Success: Usage count is 1
Success: Usage count is 1
  Erasing    : 1:mariadb-5.5.52-1.el7.x86_64                                                                           7/9
  Cleanup    : mysql-connector-odbc-5.2.5-6.el7.x86_64                                                                 8/9
  Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                      9/9
  Verifying  : mysql-community-common-5.7.17-1.el7.x86_64                                                              1/9
  Verifying  : mysql-community-server-5.7.17-1.el7.x86_64                                                              2/9
  Verifying  : mysql-connector-odbc-5.3.7-1.el7.x86_64                                                                 3/9
  Verifying  : mysql-community-libs-5.7.17-1.el7.x86_64                                                                4/9
  Verifying  : mysql-community-libs-compat-5.7.17-1.el7.x86_64                                                         5/9
  Verifying  : mysql-community-client-5.7.17-1.el7.x86_64                                                              6/9
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                                                           7/9
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                      8/9
  Verifying  : mysql-connector-odbc-5.2.5-6.el7.x86_64                                                                 9/9


Installed:
  mysql-community-client.x86_64 0:5.7.17-1.el7                   mysql-community-libs.x86_64 0:5.7.17-1.el7
  mysql-community-libs-compat.x86_64 0:5.7.17-1.el7              mysql-community-server.x86_64 0:5.7.17-1.el7


Dependency Installed:
  mysql-community-common.x86_64 0:5.7.17-1.el7


Dependency Updated:
  mysql-connector-odbc.x86_64 0:5.3.7-1.el7


Replaced:
  mariadb.x86_64 1:5.5.52-1.el7                             mariadb-libs.x86_64 1:5.5.52-1.el7


Complete!
[root@localhost yum.repos.d]#
安裝完成後,會生成一個臨時的隨機密碼給root賬戶,保存在/var/log/mysqld.log,可以使用命令查看。

四. 啓動MySQL並檢查其運行狀態


五. 完成MySQL安全相關的設置

使用mysql_secure_installation程序執行重要的安全操作,如重設root密碼,移除匿名賬戶等
[root@localhost log]# mysql_secure_installation


Securing the MySQL server deployment.


Enter password for user root:


The existing password for the user account root has expired. Please set a new password.


New password:


Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
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? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.


 - 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? (Press y|Y for Yes, any other key for No) : Y
Success.


All done!
[root@localhost log]#



發佈了31 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章