1. 程式人生 > >linux 6.5下 MySQL 5.6 RPM安裝

linux 6.5下 MySQL 5.6 RPM安裝

1.環境

OS: CentOS 6.5 x64

2.準備MySQL RPM安裝包

會看到以下介面:



Select Version: 選5.6.31,Select Platform: 選Red Hat Enterprise Linux / Oracle Linux. 

在下面的下載列表裡選Red Hat Enterprise Linux 6 / Oracle Linux 6 (x86, 64-bit), RPM Bundle,下載


3.準備安裝

將下載的MySQL-5.6.31-1.el6.x86_64.rpm-bundle.tar上傳到伺服器,解壓:

[[email protected]

mysql2]# tar -xvf MySQL-5.6.29-1.el6.x86_64.rpm-bundle.tar 
MySQL-devel-5.6.29-1.el6.x86_64.rpm
MySQL-embedded-5.6.29-1.el6.x86_64.rpm
MySQL-server-5.6.29-1.el6.x86_64.rpm
MySQL-client-5.6.29-1.el6.x86_64.rpm
MySQL-test-5.6.29-1.el6.x86_64.rpm
MySQL-shared-5.6.29-1.el6.x86_64.rpm
[[email protected]
mysql2]# 

解壓後會出現7個rpm包,我們只需要其中兩個:MySQL-server-5.6.29-1.el6.x86_64.rpm和MySQL-client-5.6.29-1.el6.x86_64.rpm。

安裝前要先查詢一下系統是否已經安裝了MySQL,如果已安裝需要先刪除,否則會報衝突:

[[email protected] mysql2]# rpm -ivh MySQL-server-5.6.29-1.el6.x86_64.rpm 
warning: MySQL-server-5.6.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
file /usr/bin/innochecksum from install of MySQL-server-5.6.29-1.el6.x86_64

conflicts with file from package MySQL-server-advanced-5.6.24-1.el6.x86_64
file /usr/bin/my_print_defaults from install of MySQL-server-5.6.29-1.el6.x86_64 conflicts with file from package MySQL-server-advanced-5.6.24-1.el6.x86_64
file /usr/bin/myisam_ftdump from install of MySQL-server-5.6.29-1.el6.x86_64 conflicts with file from package MySQL-server-advanced-5.6.24-1.el6.x86_64

。。。

[[email protected] mysql2]# rpm -qa | grep -i mysql
MySQL-client-advanced-5.6.24-1.el6.x86_64
MySQL-server-advanced-5.6.24-1.el6.x86_64
MySQL-devel-advanced-5.6.24-1.el6.x86_64

[[email protected] mysql2]# rpm -e MySQL-server-advanced-5.6.24-1.el6.x86_64     #刪除已安裝的MySQL

[[email protected] mysql2]# rpm -e MySQL-client-advanced-5.6.24-1.el6.x86_64     #客戶端也要刪除

如果刪除的由於包依賴刪除不了,報 error: Failed dependencies,可以加--nodeps方式刪除:

[[email protected] mysql2]# rpm -e --nodeps MySQL-server-advanced-5.6.24-1.el6.x86_64

4.安裝

[[email protected] mysql2]# rpm -ivh MySQL-server-5.6.29-1.el6.x86_64.rpm 
warning: MySQL-server-5.6.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2016-05-11 09:38:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

。。。

2016-05-11 09:38:38 7496 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

上面的安裝提示很重要,比如密碼檔案的位置,配置檔案位置等。預設安裝的資料目錄位置是/var/lib/mysql,要想改變安裝目錄,可以使用rpm的--prefix選項指定安裝目錄。

[[email protected] mysql2]# cd /var/lib/mysql/
[[email protected] mysql]# ls
ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  RPM_UPGRADE_HISTORY  RPM_UPGRADE_MARKER-LAST  test
[[email protected] mysql]# 

安裝完server還需要安裝client,否則server無法使用:
[[email protected] mysql2]# rpm -ivh MySQL-client-5.6.29-1.el6.x86_64.rpm 
warning: MySQL-client-5.6.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[[email protected] mysql2]# 

5.配置my.cnf

[[email protected]usr]# vi /etc/my.cnf
[mysqld]
datadir = /var/lib/mysql

就這麼簡單,只配置了一個引數,其實不配置任何引數甚至沒有my.cnf檔案都可以,只不過全部使用預設值而已。

在生產環境下mysql有許多引數要配,這裡只是樣例,所以只配置了一個引數。

6.mysql啟動、停止、狀態

[[email protected] mysql]# /etc/init.d/mysql start
Starting MySQL.                                            [  OK  ]
[[email protected] mysql]# /etc/init.d/mysql status
MySQL running (8351)                                       [  OK  ]
[[email protected] mysql]# /etc/init.d/mysql stop
Shutting down MySQL..                                      [  OK  ]
[[email protected] mysql]# /etc/init.d/mysql status
MySQL is not running                                       [FAILED]
[[email protected] mysql]# 

使用RPM包安裝,MySQL會自動新增到系統服務並可以開機自動啟動。

7.修改root密碼

mysql服務啟動後第一件事是修改root密碼。用RPM方式安裝的MySQL5.6不能再用mysqladmin來修改root密碼了,要用安裝時生成的密碼登入後再修改密碼,安裝時生成的密碼在/root/.mysql_secret檔案裡。

[[email protected] mysql]# mysqladmin -uroot password
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[[email protected] mysql]# cd 

[[email protected] ~]# ls -a .mysql*
.mysql_history  .mysql_secret
[[email protected] ~]# cat .mysql_secret 
# The random password set for the root user at Wed May 11 09:38:34 2016 (local time): FloC99GoZUfjkqhg

[[email protected] ~]# mysql -uroot -pFloC99GoZUfjkqhg
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 3
Server version: 5.6.29
Copyright (c) 2000, 2016, 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> set password=password('root');

mysql> exit
Bye
[[email protected] mysql]# mysql -uroot -proot #用新密碼登入
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 2
Server version: 5.6.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> 

成功。

MySQL RPM方式安裝完成。