【MySQL】源碼編譯安裝和配置MySql 5.5.32(單一實例)

來源:互聯網
上載者:User

標籤:

【需求描述】

       在CentOS環境中,通過編譯源碼的方式,安裝並且配置“單一實例”的MySQL5.5.32資料庫。

       MySQL的安裝目錄為:/application/mysql-5.5.32

       MySQL資料檔案的安裝目錄為:/application/mysql-5.5.32/data

       MySQL預設的字元編碼為:UTF8

 

【環境參數】

VMware:10.0.1

Host:Win7

DB:MySql 5.5.32

編譯工具:cmake-2.8.8.tar.gz

其他依賴:ncurses-devel-5.7-3.20090208.el6.x86_64.rpm

Client:CentOS 6.5 x86_64,i686,迷你安裝(Minimal)。

在安裝自訂群組件包時,

(1)Base System只安裝了Base,Compatibility Libraries和Debugging Tools。

(2)Development只安裝了Development Tools。

 

【軟體下載】

(1)MySql:

http://downloads.mysql.com/archives/community/?tpl=files&os=src&version=5.5.33

選擇“Generic Linux (Architecture Independent), Compressed TAR Archive”這個版本的來下載。

(2)下載cmake

cmake的百度雲端硬碟串連:http://pan.baidu.com/s/1dDAWXsl 

CMake是一個跨平台的安裝(編譯)工具,可以用簡單的語句來描述所有平台的安裝(編譯過程)。他能夠輸出各種各樣的makefile或者project檔案,能測試編譯器所支援的C++特性,類似UNIX下的automake。只是 CMake 的組態檔取名為 CmakeLists.txt。 

(3)下載ncurse-devel依賴包

ncurses-devel-5.7-3.20090208.el6.x86_64.rpm的百度雲端硬碟分享:

http://pan.baidu.com/s/1pJpDRCJ

 

【具體步驟】

1、查看系統內容 

[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# uname -r
2.6.32-431.el6.x86_64
[[email protected] ~]#

 

2、安裝相關軟體包
(1) 配置、編譯和安裝cmake編譯工具
①在目前的目錄,解壓縮cmake-2.8.8.tar.gz
# tar –zxvf cmake-2.8.8.tar.gz

②從目前的目錄切換到cmake-2.8.8目錄中,
# cd cmake-2.8.8

③執行命令“#./configure”來配置cmake工具。
# ./configure

④編譯cmake工具
在cmake配置完成後,會有如下提示:

之後,執行gmake命令,來進行編譯工作,

# gmake

⑤檢查上一條“gmake”命令是否執行成功。
[[email protected] cmake-2.8.8]# echo $?
0
解釋:“echo $?”表示顯示上一條命令執行的結果,若傳回值為0,則表示上一條命令執行成功。

⑥安裝cmake工具
# gmake install

⑦安裝完成後,返回上一級目錄
# cd ..

 

(2) 安裝依賴包
1)安裝ncurse-devel依賴包
yum install ncurse-devel -y

若yun無法安裝,則去網上下載“ncurses-devel-5.7-3.20090208.el6.x86_64.rpm ”這個rpm包。

ncurses-devel-5.7-3.20090208.el6.x86_64.rpm的百度雲端硬碟分享:http://pan.baidu.com/s/1pJpDRCJ

 

3、建立mysql使用者和mysql使用者組
[[email protected] /]# groupadd mysql
[[email protected] /]# useradd mysql -s /sbin/nologin -M -g mysql
命令說明:
①“–s /sbin/nologin”:表示禁止該使用者登入,加強安全。
②“–g mysql”:指定屬於mysql組。
③“–M”:表示不建立使用者家目錄。

檢查建立的使用者
[[email protected] ~]# tail -1 /etc/passwd
mysql:x:500:500::/home/mysql:/sbin/nologin

注意:是參數是“數字1”,而不是字母“l”。

 

4、解壓、編譯和安裝mysql軟體(重要)
(0)建立mysql的安裝目錄
[[email protected] /]# mkdir –p /application/mysql-5.5.32

(1)在臨時目錄中,解壓縮源碼包:mysql-5.5.32.tar.gz
# tar –zxvf mysql-5.5.32 ./

(2)編譯mysql
切換到解壓縮後的mysql-5.5.32源碼目錄下,執行下列cmake命令,進行編譯(重要)
注意01:下述cmake命令可以重複使用。
注意02:目錄“/application/mysql-5.5.32”為使用者自訂的“mysql安裝目錄”。
注意03:提示:編譯時間,可配置的選項有很多,具體可以參考結尾附錄或者官方文檔。
官方文檔mysql5.1_chs.chm,2.8. 使用源碼分發版安裝MySQL

下述命令很重要,可以複用。

cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 -DMYSQL_DATADIR=/application/mysql-5.5.32/data -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSET=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=on -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPL_ESTORAGE_ENGINE=1 -DWITHOUT_PARTITION_ESTORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_ENBEDDED_SERVER=1 -DWITH_DEBUG=0

編譯完成後,有如下提示:

-- Build files have been written to: /root/zj-tools/mysql-5.5.32
[[email protected] mysql-5.5.32]#

 

(3)安裝mysql

# make && make install

如果上述安裝過程中沒有出錯,則至此,就完成了MySql軟體的安裝。在安裝完成之後,就會在根目錄下出現一個“application”的檔案夾,如所示。

 

(4)建立一個Link檔案
# ln –s /application/mysql-5.5.32/ /application/mysql


(5)提醒的事項
至此,就完成了以編譯源碼的方式安裝MySQL,安裝完MySQL資料庫後,還要進行各種配置,接下來就需要對MySql進行配置。
若要安裝“多執行個體”MySQL資料庫,則下列“配置、初始化單一實例的MySQL資料檔案和服務”筆記可以跳過去

 

5、配置、初始化單一實例的MySQL資料檔案和服務(單一實例,重要)

5.1、查看預設模版設定檔
在MySql-5.5.32的源碼安裝目錄下有一個檔案夾“support-files”,MySQL常用的各種模版設定檔都在該目錄下存放的。

[[email protected] mysql-5.5.32]# pwd
/root/zj-tools/mysql-5.5.32
[[email protected] mysql-5.5.32]# cd support-files/
[[email protected] support-files]# ls
binary-configure magic mysql-log-rotate.sh
binary-configure.sh Makefile mysql.m4
build-tags my-huge.cnf mysql-multi.server.sh
CMakeFiles my-huge.cnf.sh mysql.server
cmake_install.cmake my-innodb-heavy-4G.cnf mysql.server.sh
CMakeLists.txt my-innodb-heavy-4G.cnf.sh mysql.server-sys5.sh
compiler_warnings.supp my-large.cnf MySQL-shared-compat.spec
config.huge.ini my-large.cnf.sh MySQL-shared-compat.spec.sh
config.huge.ini.sh my-medium.cnf mysql.spec
config.medium.ini my-medium.cnf.sh mysql.spec.sh
config.medium.ini.sh my-small.cnf ndb-config-2-node.ini
config.small.ini my-small.cnf.sh ndb-config-2-node.ini.sh
config.small.ini.sh mysql.5.5.32.spec plugins.files
CTestTestfile.cmake mysqld_multi.server RHEL4-SElinux
dtrace mysqld_multi.server.sh
MacOSX mysql-log-rotate
[[email protected] support-files]#

 

5.2、選擇設定檔

測試環境選擇小的,生產環境可以根據硬體選擇,例如:my-innodb-heavy-4G.cnf
下列命令將MySQL來源目錄下的設定檔拷貝到“/etc”目錄下。

[[email protected] support-files]# cp my-small.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf‘? y
[[email protected] support-files]#

 

5.3、配置環境變數

# echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile
# tail -l /etc/profile
# source /etc/profile
# echo $PATH

此處注意:“/application/mysql/bin”路徑與“$PATH”的先後順序問題。
要將“/application/mysql/bin”放置在“$PATH”的前邊,這樣的話當使用mysql相關的命令時,就會先去尋找編譯的MySql這個版本的命令。
因為,未來的生產系統中,有可能已經存在yum或者rpm方式安裝的mysql,這樣的話,當使用mysqldump等mysql命令時,會先去尋找已經存在的mysql命令。
即使用yum或者rpm安裝的用戶端會去串連“編譯版本的”MySql服務端,從而造成驢頭不對馬嘴的錯誤。

故障案例:
由於“/application/mysql/bin”路徑放置在“$PATH”後邊,而出現的棘手錯誤案例:
http://oldboy.blog.51cto.com/2561410/1122867

 

5.4、初始化資料檔案(容易出錯的步驟)
# mkdir –p /application/mysql/data
建立mysql資料檔案目錄,若在安裝mysql軟體的過程中已經建立了,則不需要建立該目錄。

修改資料檔案所在目錄的使用者和使用者組
# chown –R mysql:mysql /application/mysql/data

調整/tmp許可權,否則初始化會錯誤。
# chmod –R 1777 /tmp

安裝mysql資料庫檔案,注意命令路徑:
mysql的初始化指令碼
[[email protected] scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

特別提示:如果用mysql5.0,5.1,省略指定datadir會出錯。
下列為初始化成功後,MySQL的一些內建資訊,其中包括設定和修改MySql的使用者密碼等。

 1 WARNING: The host ‘centos65-mini‘ could not be looked up with resolveip. 2 This probably means that your libc libraries are not 100 % compatible 3 with this binary MySQL version. The MySQL daemon, mysqld, should work 4 normally with the exception that host name resolving will not work. 5 This means that you should use IP addresses instead of hostnames 6 when specifying MySQL privileges ! 7 Installing MySQL system tables... 8 OK 9 Filling help tables...10 OK11 12 To start mysqld at boot time you have to copy13 support-files/mysql.server to the right place for your system14 15 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !16 To do so, start the server, then issue the following commands:17 18 /application/mysql/bin/mysqladmin -u root password ‘new-password‘19 /application/mysql/bin/mysqladmin -u root -h centos65-mini password ‘new-passwor                d‘20 21 Alternatively you can run:22 /application/mysql/bin/mysql_secure_installation23 24 which will also give you the option of removing the test25 databases and anonymous user created by default.  This is26 strongly recommended for production servers.27 28 See the manual for more instructions.29 30 You can start the MySQL daemon with:31 cd /application/mysql ; /application/mysql/bin/mysqld_safe &32 33 You can test the MySQL daemon with mysql-test-run.pl34 cd /application/mysql/mysql-test ; perl mysql-test-run.pl35 36 Please report any problems with the /application/mysql/scripts/mysqlbug script!37 38 [[email protected] scripts]#

【拓展】
WARNING: The host ‘centos65-mini‘ could not be looked up with resolveip.”
該警告資訊對MySQL的功能不會造成影響,但是,可以通過以下設定來消除掉該警告。

原因:主機名稱與IP地址的映射問題。
解決方案:vim hosts,將原生主機名稱添加到該檔案中。

 

5.5、初始化並且配置MySql的服務mysqld
(1)配置MySQL的服務mysqld
進入MySql-5.5.32的源碼安裝目錄下的檔案夾“support-files”,將其中的“mysql.server”拷貝到目錄“/etc/init.d/mysqld”下。
[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld
[[email protected] support-files]#
[[email protected] support-files]# chmod +x /etc/init.d/mysqld
[[email protected] support-files]#

(2)啟動MySQL伺服器
[[email protected] support-files]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[[email protected] support-files]#

(3)確認MySQL伺服器是否啟動成功:
[[email protected] support-files]# netstat -lntup | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 36586/mysqld
[[email protected] support-files]#

 

5.6、設定使用者名稱和密碼,並且登入MySql伺服器
(1)設定MySql資料的使用者名稱和密碼
[[email protected] support-files]# /application/mysql/bin/mysqladmin -u root password ‘new-password‘
[[email protected] support-files]# /application/mysql/bin/mysqladmin -u root -h centos65-mini password ‘new-passwor d‘

(2)登入到MySQL資料庫伺服器
[[email protected] support-files]# mysql -uroot -pnew-password

 

至此,MySQL的基本配置完成。

【MySQL】源碼編譯安裝和配置MySql 5.5.32(單一實例)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.