天天看點

CentOS 7 yum安裝MySQL5.6

衆所周知,Linux系統自帶的repo是不會自動更新每個軟體的最新版本(基本都是比較靠後的穩定版),是以無法通過yum方式安裝MySQL的進階版本。是以我們需要先安裝帶有目前可用的mysql5系列社群版資源的rpm包。

#安裝rpm包

Bash

[root@typecodes ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm           
Retrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-el7-5    ################################# [100%]           

這時檢視目前可用的mysql安裝資源:

[root@typecodes ~]# yum repolist enabled | grep "mysql.*-community.*"           
mysql-connectors-community/x86_64 MySQL Connectors Community                 14
mysql-tools-community/x86_64      MySQL Tools Community                      17
mysql56-community/x86_64          MySQL 5.6 Community Server                139           

從上面的清單可以看出, mysql56-community/x86_64 和 MySQL 5.6 Community Server 可以使用。

是以,我們就可以直接用yum方式安裝了MySQL5.6版本了。

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

3 MySQL安裝完成後,進行相關配置

安裝完MySQL後,需要進行一些基礎配置工作:

#安裝成功後,将其加入開機啟動

[root@typecodes ~]# systemctl enable mysqld           

#啟動mysql服務程序

[root@typecodes ~]# systemctl start mysqld           
[root@typecodes ~]# 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, andyou 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 anyoneto log into MySQL without having to have a user account created forthem.  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 removedbefore 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 -uroot -p           
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;