標籤:blank 伺服器 target linux 二進位
一.準備工作
首先是檔案準備,咳咳,由於那啥沒有搭配ftp環境去儲存工具類檔案,就使用Xftp複製粘貼下MySQL的通用二進位格式檔案,無論是移動儲存掛載還是其他的,目的就是把這玩意放到linux伺服器中。這裡使用的版本檔案為“mysql-5.5.33-linux2.6-x86_64.tar.gz”,檔案大家可以去www.mysql.com或其他鏡像網站下載。
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599850iQis.png" width="1026" height="577" />
二.開始配置
1.另設MySQL的data存放路徑,最好是掛載,這樣利於後期資料龐大方便擴充神馬的,這裡偷個懶就不做掛載操作了,我直接在根目錄下建立了/mydata/mysql/data,建立系統使用者mysql;
將/mydata/mysql/data的屬主、屬組設定為mysql:
# mkdir -p /mydata/mysql/data# useradd -r mysql# chown -R mysql.mysql /mydata/mysql/data
完成操作後,需要檢查下是否有誤,馬哥經常都會提醒我們這樣操作;
檢查ing:
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599850G77U.png" width="450" height="105" />
2.將檔案解壓到usr/local/中;
# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local /*參數-C 指定解壓路徑*/
解壓完後,查看3306連接埠是否被佔用,如被佔用需要關閉;
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599850tbhL.png" width="566" height="183" />
通常MySQL程式放在/usr/local/mysql目錄下,但這裡不建議改檔案名稱,做一個檔案名稱連結即可;
# ln -sv mysql-5.5.33-linux2.6-x86_64/ mysql /*建立檔案連結*/
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599851TAjS.png" width="712" height="120" />
3.改檔案屬主、屬組
注意:mysql中的data需要屬主、屬組都為mysql,其他檔案的屬主、屬組分別是root、mysql,由於我們另設其data檔案路徑,所以這裡直接將/usr/local/mysql的屬主、屬組統一改為root、mysql;
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599851jlIG.png" width="438" height="281" />
# chown -R root.mysql /usr/local/mysql/* /*更改屬主、屬組*/
改後並檢查,注意這裡改的是mysql目錄中檔案的屬主、屬組,不要改mysql本身的屬主、屬組;
650) this.width=650;" style="background-image: none; border-right- 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599911CuUT.png" width="450" height="279" />
4.將support-files下的my-large.cnf複製到/etc下並將檔案名稱改為my.cnf,通過查看my-huge.cnf,my-large.cnf,my-medium.cnf,my-small.cnf檔案對比linux伺服器記憶體大小選擇相對應檔案;
# cp my-large.cnf /etc/my.cnf
這裡會提示是否要覆蓋,這裡要注意的是,生產環境中有類似修改、刪除、覆蓋等操作時,需要有備份檔案的習慣,方便出現問題時及時恢複;
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599911uxZQ.png" width="427" height="38" />
然後修改/etc/my.cnf檔案,在檔案以下內容後增加紅色部分,即完成修改資料目錄
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 8 / *此處為並發線程數,數量是物理核心的2倍或與物理核心數相同*/
datadir = /mydata/mysql/data
將support-files下的mysql.server複製到/etc/rc.d/init.d/下並將檔案名稱改為mysqld,然後將mysqld添加到服務列表中;
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld# chkconfig --add mysqld /*將mysqld添加到服務列表中*/
查看
# chkconfig --list mysqld
5.然後運行服務,
# service mysqld star
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599912hIg2.png" width="813" height="54" />
這裡報錯了,原因是沒有更新/usr/local/mysql/data/localhost.localdomain.pid這個設定檔。
然後查看這個路徑,裡面是沒有這個pid檔案的,
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599912fIit.png" width="345" height="39" />
這裡我們可以看下錯誤記錄檔localhost.localdomain.err,它告訴我們各種表不存在,所以啟動不了,這種情況我們需要手動初始化一次;
首先清空/usr/local/mysql/data/目錄,
# rm -rf /usr/local/mysql/data/*
然後運行初始化指令檔,檔案路徑/usr/local/mysql/scripts/mysql_install_db
# /usr/local/mysql/scripts/mysql_install_db --help /*查看指令碼協助*/
這裡我們需要用到參數
--user= 指定mysql使用者名稱
--datadir 指定資料目錄
# scripts/mysql_install_db --user=mysql --datadir=/mydata/mysql/data /*初始化*/
提示成功
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599913L21n.png" width="641" height="523" />
初始化後,可以看到/mydata/mysql/data/下已經產生了新的檔案,
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599913oXTL.png" width="610" height="44" />
此時再啟動mysql服務,成功!
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599913NpMr.png" width="321" height="55" />
此時可以查看連接埠3306已監聽,表示mysql成功啟動;
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599914Pf6Z.png" width="768" height="195" />
6.用戶端串連,出現提示,這是因為path環境變數沒有設定,
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599914RMFn.png" width="249" height="40" />
我們動手設定一下,
# vim /etc/profile.d/mysql.sh
編輯如下內容後儲存:
export PATH=/usr/local/mysql/bin:$PATH
執行一次指令碼,然後嘗試用戶端串連,成功!
650) this.width=650;" style="background-image: none; border-right- 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://img1.51cto.com/attachment/201407/29/2784219_1406599914RrSM.png" width="563" height="248" />