CentOS 6.4 安裝MySQL 5.6.22

來源:互聯網
上載者:User

CentOS 6.4 安裝MySQL 5.6.22

本文詳細介紹在CentOS 6.4下安裝MySQL 5.6.22的過程,供需要的朋友學習參考。

一、下載MySQL 安裝包

1)http://dev.mysql.com/downloads/mysql/ 開啟網址: Select Platform: 選擇 Linux-Generic選擇選擇 Linux - Generic (glibc 2.5) (x86, 64-bit), RPM   進行下載; linux 下下載: wget  http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tar 2)下載完後解壓縮並放到安裝資料夾下:tar -xf MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle.tarmv MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle /usr/local/software/mv MySQL-5.6.22-1.linux_glibc2.5.x86_64.rpm-bundle mysql其中裡面要使用的是這兩個:MySQL資料庫: MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpmMySQL用戶端:MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpm 3)安裝環境:cat /etc/RedHat-release  CentOS release 6.4 (Final) 二、MySql安裝1)3)檢查安裝在安裝MySQL之前,先檢查CentOS系統中是否已經安裝了一個MySQL,如果已經安裝先卸載,不然會導致安裝新的MySQL失敗。 rpm -qa | grep mysql   --查看系統之前是否已安裝MySQL。 

mysql-libs-5.1.47-4.el6.i686  顯示結果說明 CentOS6.0系統內建了一個MySQL,我們需要刪除這個老版本,用root使用者執行下面語句

su - 密碼:
rpm -e --nodeps mysql-libs-5.1.47-4.el6.i686 
先切換到"root"使用者下,然後執行刪除語句,刪除之後,我們再次查看,發現已經成功刪除了CentOS6.0內建的舊MySQL版本。在刪除MySQL的rpm後,還要進行一些掃尾操作,網上有兩種操作。(備忘:我在這裡兩種都沒有用到,發現系統中並沒有其他殘餘的MySQL資訊。)第一種善後處理:使用下面命令進行處理。rm -rf /var/lib/mysql*rm -rf /usr/share/mysql*另一種善後處理:卸載後 /var/lib/mysql 中的  /etc/my.cnf 會重新命名為 my.cnf.rpmsave,/var/log/mysqld.log 會重新命名為 /var/log/mysqld.log.rpmsave,如果確定沒用後就手工刪除。 2)安裝MySql 服務端rpm -ivh MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpm 
Preparing... ########################################### [100%] 
1:MySQL-server ########################################### [100%] 
warning: user mysql does not exist - using root 
warning: group mysql does not exist - using root 
2014-08-10 22:43:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 
2014-08-10 22:43:44 23012 [Note] InnoDB: Using atomics to ref count buffer pool pages 
2014-08-10 22:43:44 23012 [Note] InnoDB: The InnoDB memory heap is disabled 
2014-08-10 22:43:44 23012 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 
2014-08-10 22:43:44 23012 [Note] InnoDB: Memory barrier is not used 
2014-08-10 22:43:44 23012 [Note] InnoDB: Compressed tables use zlib 1.2.3 
2014-08-10 22:43:44 23012 [Note] InnoDB: Using Linux native AIO 
2014-08-10 22:43:44 23012 [Note] InnoDB: Not using CPU crc32 instructions 
2014-08-10 22:43:44 23012 [Note] InnoDB: Initializing buffer pool, size = 128.0M 
2014-08-10 22:43:44 23012 [Note] InnoDB: Completed initialization of buffer pool 
2014-08-10 22:43:45 23012 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 
2014-08-10 22:43:45 23012 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 
2014-08-10 22:43:45 23012 [Note] InnoDB: Database physically writes the file full: wait... 
2014-08-10 22:43:45 23012 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 
2014-08-10 22:43:46 23012 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 
2014-08-10 22:43:46 23012 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 
2014-08-10 22:43:46 23012 [Warning] InnoDB: New log files created, LSN=45781 
2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer not found: creating new 
2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer created 
2014-08-10 22:43:46 23012 [Note] InnoDB: 128 rollback segment(s) are active. 
2014-08-10 22:43:46 23012 [Warning] InnoDB: Creating foreign key constraint system tables. 
2014-08-10 22:43:47 23012 [Note] InnoDB: Foreign key constraint system tables created 
2014-08-10 22:43:47 23012 [Note] InnoDB: Creating tablespace and datafile system tables. 
2014-08-10 22:43:47 23012 [Note] InnoDB: Tablespace and datafile system tables created. 
2014-08-10 22:43:47 23012 [Note] InnoDB: Waiting for purge to start 
2014-08-10 22:43:47 23012 [Note] InnoDB: 5.6.22 started; log sequence number 0 
A random root password has been set. You will find it in '/root/.mysql_secret'. 
2014-08-10 22:43:48 23012 [Note] Binlog end 
2014-08-10 22:43:48 23012 [Note] InnoDB: FTS optimize thread exiting. 
2014-08-10 22:43:48 23012 [Note] InnoDB: Starting shutdown... 
2014-08-10 22:43:50 23012 [Note] InnoDB: Shutdown completed; log sequence number 1625977 


2014-08-10 22:43:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 
2014-08-10 22:43:50 23039 [Note] InnoDB: Using atomics to ref count buffer pool pages 
2014-08-10 22:43:50 23039 [Note] InnoDB: The InnoDB memory heap is disabled 
2014-08-10 22:43:50 23039 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 
2014-08-10 22:43:50 23039 [Note] InnoDB: Memory barrier is not used 
2014-08-10 22:43:50 23039 [Note] InnoDB: Compressed tables use zlib 1.2.3 
2014-08-10 22:43:50 23039 [Note] InnoDB: Using Linux native AIO 
2014-08-10 22:43:50 23039 [Note] InnoDB: Not using CPU crc32 instructions 
2014-08-10 22:43:50 23039 [Note] InnoDB: Initializing buffer pool, size = 128.0M 
2014-08-10 22:43:50 23039 [Note] InnoDB: Completed initialization of buffer pool 
2014-08-10 22:43:50 23039 [Note] InnoDB: Highest supported file format is Barracuda. 
2014-08-10 22:43:50 23039 [Note] InnoDB: 128 rollback segment(s) are active. 
2014-08-10 22:43:50 23039 [Note] InnoDB: Waiting for purge to start 
2014-08-10 22:43:50 23039 [Note] InnoDB: 5.6.22 started; log sequence number 1625977 
2014-08-10 22:43:50 23039 [Note] Binlog end 
2014-08-10 22:43:50 23039 [Note] InnoDB: FTS optimize thread exiting. 
2014-08-10 22:43:50 23039 [Note] InnoDB: Starting shutdown... 
2014-08-10 22:43:52 23039 [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 

3)檢測 MySQL 3306 連接埠是否安開啟。測試是否成功可運行 netstat 看 MySQL 連接埠是否開啟,如開啟表示服務已經啟動,安裝成功。MySQL 預設的連接埠是3306。
[root@hadoop Mysql]# netstat -nat  
Active Internet connections (servers and established) 
Proto Recv-Q Send-Q Local Address Foreign Address State 
tcp 0 0 0.0.0.0:50070 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50010 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50075 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50020 0.0.0.0:* LISTEN 
tcp 0 0 192.168.128.129:9000 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:50090 0.0.0.0:* LISTEN 
tcp 1 0 192.168.128.129:35744 63.130.76.64:80 CLOSE_WAIT 
tcp 0 0 192.168.128.129:34847 192.168.128.129:9000 ESTABLISHED 
tcp 0 0 192.168.128.129:35770 192.168.128.129:9000 TIME_WAIT 
tcp 0 52 192.168.128.129:22 192.168.128.1:1297 ESTABLISHED 
tcp 0 0 192.168.128.129:50968 61.135.185.247:80 ESTABLISHED 
tcp 0 0 192.168.128.129:9000 192.168.128.129:34847 ESTABLISHED 
tcp 0 0 :::34803 :::* LISTEN 
tcp 0 0 :::22 :::* LISTEN 
tcp 0 0 ::1:631 :::* LISTEN 
tcp 0 0 :::8088 :::* LISTEN 
tcp 0 0 :::13562 :::* LISTEN 
tcp 0 0 :::8030 :::* LISTEN 
tcp 0 0 :::8031 :::* LISTEN 
tcp 0 0 :::8032 :::* LISTEN 
tcp 0 0 :::8033 :::* LISTEN 
tcp 0 0 :::8040 :::* LISTEN 
tcp 0 0 :::8042 :::* LISTEN 
tcp 0 0 ::ffff:192.168.128.129:8031 ::ffff:192.168.128.12:58051 ESTABLISHED 
tcp 0 0 ::ffff:192.168.128.12:58051 ::ffff:192.168.128.129:8031 ESTABLISHED  4)啟動MySql 服務
[root@hadoop Mysql]# service mysql start  
Starting MySQL.......... SUCCESS!  5) 安裝用戶端
[root@hadoop Mysql]# rpm -ivh MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpmPreparing...                ########################################### [100%]1:MySQL-client           ^C########################################### [100%]   安裝完成 5)MySQL的幾個重要目錄。MySQL安裝完成後不像 SQL Server 預設安裝在一個目錄,它的資料庫檔案、設定檔和命令檔案分別在不同的目錄,瞭解這些目錄非常重要,尤其對於Linux的初學者,因為 Linux本身的目錄結構就比較複雜,如果搞不清楚MySQL的安裝目錄那就無從談起深入學習。a、資料庫目錄     /var/lib/mysql/ b、設定檔     /usr/share/mysql(mysql.server命令及設定檔) c、相關命令    /usr/bin(mysqladmin mysqldump等命令) d、啟動指令碼   /etc/rc.d/init.d/(啟動指令檔mysql的目錄) 如:/etc/rc.d/init.d/mysql start/restart/stop/status 6)更改 MySQL 目錄。由於MySQL資料庫目錄佔用磁碟比較大,而MySQL預設的資料檔案儲存目錄為 /"var/lib/mysql",也可以把要把資料目錄移到 "/" 根目錄下的 "mysql_data" 目錄中(如果做測試用就不用移動了)。 停止 MySql 服務進程:service mysql stop  或者  mysqladmin -u root -p shutdownMySQL預設使用者名為"root",此處的"root"與Linux的最高許可權使用者"root"不是一會兒,而且預設的使用者"root"的密碼為空白,所以中讓輸入密碼,直接點擊斷行符號即可。把 "/var/lib/mysql" 整個目錄移到 "/mysql_data"mv /var/lib/mysql /mysql_data 找到my.cnf設定檔如果"/etc/"目錄下沒有my.cnf設定檔,請到 "/usr/share/mysql/" 下找到 my-default.cnf  檔案,拷貝其中一個合適的設定檔到 "/etc/" 並改名為 "my.cnf" 中。命令如下:cp /usr/share/mysql/my-medium.cnf  /etc/my.cnf  編輯MySQL的設定檔 "/etc/my.cnf" 為保證MySQL能夠正常工作,需要指明"mysql.sock"檔案的產生位置,以及預設編碼修改為UTF-8。用下面命令:vim /etc /my.cnf[mysqld] #下添加以下命令socket = /var/lib/mysql/mysql/mysql.sockdatadir=/mysql_data/mysql   #如果你的資料存放區位置要改變的話需要在這裡指定儲存目錄
character-set-server=utf8

 

lower_case_table_names=1  #(注意linux下mysql安裝完後是預設:區分表名的大小寫,不區分列名的大小寫;#  lower_case_table_names = 0    0:區分大小寫,1:不區分大小寫)注意:1)最後一行,我在本地安裝的時候沒有添加此設定也可以照樣運行起來,加不加還要看你們自己了。2)還有在此設定檔還有 [client] 的一下配置 其中也可以設定 socket ,datadir 兩個選項,我這裡也沒有(此處不做配置,因為只是安裝 MySql 測試用),不知道是版本的原因還是什麼,如果大家需要弄清楚這個怎麼使用,那就自己先百度一下吧;3)如果你修改了資料的儲存位置目錄 ,則可以執行以下命令來修改MySQL啟動指令碼 "/etc/rc.d/init.d/mysql"  最後,需要修改MySQL啟動指令碼 /etc/rc.d/init.d/mysql,修改 datadir=/mysql_data/mysql。 vim /etc/rc.d/init.d/mysql 7)重新啟動MySQL服務 service mysql start發生錯誤:Starting MySQL ERROR! The server quit without updataing PID file....經百度後解決方案是:vi  /etc/selinux/config把 SELINUX=enforcing 改為 SELINUX=disabled 後存檔退出重啟機器試試,必須要重啟,很關鍵。 千辛萬苦重啟後盼望著能管用,結果 伺服器啟動不了了。。。。。顯示錯誤:Kernel panic - not syncing: Attempted to kill init   PS:太糟心了,安裝個MySQL 費這麼大的勁。。。 經過百度又找到新的解決文案:解決辦法 系統啟動的時候,按下 ‘e’ 鍵進入 grub 編輯介面,編輯 grub 菜單,選擇 “kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quiet”  一欄,按‘e’鍵進入編輯,在末尾增加enforcing=0,即:kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quiet enforcing=0
按‘b’鍵繼續引導,OK順利前進。 好吧終於順利進入到 Linux 系統,啟動MySQL 服務:service mysql start又提示錯誤:MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解決辦法是因為 MySQL 沒有初始化表/usr/bin/mysql_install_db --user=mysqlservice mysql start 就可以重啟MySQL 服務了。 PS:安裝個MySql 著實不容易啊。。。。。 8)修改登入密碼MySQL預設沒有密碼,安裝完畢增加密碼的重要性是不言而喻的。修改前,直接登入檢查 MySql 連接埠是否開啟:[root@Hadoop ~]#netstat -ntlp  | grep 3306tcp        0      0 :::3306                     :::*                        LISTEN      5052/mysqld   $:mysql報錯:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)發現 與設定 MySql 伺服器的 socket 位置不一樣。改一下 /etc/my.cn修改 socket = /var/lib/mysql/mysql.sock   --儲存; 再次進入:[root@hadoop init.d]# mysql 又報錯。。。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)百度一下解決方案:[root@hadoop ~]#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  mysql -u root mysql 再次進入:[root@hadoop ~]# mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.22 MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> OK 了總算安裝成功了。。。 在沒有添加密碼前,直接輸入"mysql"就能登入到MySQL資料庫裡。 修改登入密碼:[root@hadoop ~]mysqladmin -u root password 'root'格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼  如果已經串連上了 MySql 可以使用下面語句 :mysql> use mysql; 
mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';Query OK, 4 rows affected (0.04 sec)Rows matched: 4  Changed: 4  Warnings: 0修改成功;

--------------------------------------分割線 --------------------------------------

Ubuntu 14.04下安裝MySQL

《MySQL權威指南(原書第2版)》清晰中文掃描版 PDF

Ubuntu 14.04 LTS 安裝 LNMP Nginx\PHP5 (PHP-FPM)\MySQL

Ubuntu 14.04下搭建MySQL主從伺服器

Ubuntu 12.04 LTS 構建高可用分布式 MySQL 叢集

Ubuntu 12.04下原始碼安裝MySQL5.6以及Python-MySQLdb

MySQL-5.5.38通用二進位安裝

--------------------------------------分割線 --------------------------------------

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.