mysql 5.5和5.6需要使用cmake虽缕,跟以往的mysql編譯有了一點(diǎn)區(qū)別(以往的是configure,make蒲稳,make install三部曲)
一共需要的軟件如下:
軟件 | 版本 | 安裝
------------- | -------------
cmake | make | yum install cmake
make | 3.75以上 | yum install make
Perl | | yum install perl
bison | 1.75 and 2.1(1.875不能用) | yum install bison-devel
gcc-c++ | 4.2.1或以上 | yum install gcc-c++
ncurses | | yum install ncurses-devel
備注:centos 6.5支持很好氮趋,基本上只要安裝以下的就不會(huì)有問(wèn)題,關(guān)閉selinux
參考: http://dev.mysql.com/doc/refman/5.6/en/source-installation.html
編譯安裝
一般編譯腳本:
#!/bin/bash
cd mysql源碼目錄
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/app/mysql/mysql/data \
-DSYSCONFDIR=/app/mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make
make install
cp ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
保存為bash腳本文件然后執(zhí)行即可江耀。
備注:
1.常用的參數(shù)就是以上的剩胁,其他的
參考:
http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
2.出現(xiàn)提示
Googletest was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://foo.bar.com:80
Configuring done
Generating done
Build files have been written to: /root/soft/mysql-5.6.4-m7
googletest,一個(gè)很著名的C++單元測(cè)試框架祥国,簡(jiǎn)稱gtest昵观,有豐富的文檔可以參考晾腔。
所以暫時(shí)我們不需要,加上參數(shù)-DENABLE_DOWNLOADS=0 就不會(huì)提示的啊犬,不過(guò)即便是提示了灼擂,但因?yàn)閏onfigure done了,所以也沒(méi)關(guān)系觉至。并且cmake的配置緩存會(huì)存放在當(dāng)前文件夾的CMakeCache.txt文件缤至,需要重新編譯就只需要?jiǎng)h掉這個(gè)文件即可。
3.mysql 5.5的安裝包里面沒(méi)有my.cnf參考文件(在源碼包的support-files目錄下),5.6的包和5.1以前的包里面都有,非常怪異- -,而且不同的文件(my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf)分別對(duì)應(yīng)不同使用規(guī)模等級(jí)的mysql配置,以下是文件使用的優(yōu)先級(jí),從上到下排序,當(dāng)?shù)谝粚訖z查到?jīng)]有文件的時(shí)候就會(huì)去搜索第二層的文件,如此類推.
文件路徑 | 用途 |備注
------------- | -------------
/etc/my.cnf | 全局使用
/etc/mysql/my.cnf | 全局使用
SYSCONFDIR/my.cnf | Global options
$MYSQL_HOME/my.cnf | 服務(wù)器配置指定位置|這個(gè)就是編譯參數(shù)-DSYSCONFDIR的對(duì)應(yīng)位置
defaults-extra-file | 由--defaults-extra-file=path這個(gè)配置決定
~/.my.cnf | 用戶特別配置
~/.mylogin.cnf | 登錄配置
詳情參考:http://dev.mysql.com/doc/refman/5.6/en/option-files.html
至此編譯安裝完成.
初始化數(shù)據(jù)庫(kù)
因?yàn)榘惭b完成后mysql并沒(méi)有數(shù)據(jù)庫(kù),主要是沒(méi)有名字為mysql的數(shù)據(jù)庫(kù),這個(gè)數(shù)據(jù)庫(kù)會(huì)存放mysql賬號(hào),權(quán)限等一系列的信息,是中樞,是數(shù)據(jù)庫(kù)的大腦,所以需要初始化,
進(jìn)入mysql的安裝目錄并執(zhí)行初始化腳本
cd /app/mysql/scripts
./mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data
1.錯(cuò)誤提示
./mysql_install_db --user=mysql
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
需要有basedir和datadir
2.出現(xiàn)warning
WARNING: The host 'testyuan' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
需要使用主機(jī)名康谆,如果用不了話就只能用ip领斥,并且可能有些libc庫(kù)不能100%兼容
就加個(gè)主機(jī)名的hosts就好了,但只是warning,影響級(jí)別低.
啟動(dòng)數(shù)據(jù)庫(kù)并設(shè)置root密碼
可以安裝提示使用mysqld_safe 啟動(dòng),然后修改密碼
mysqladmin -u root password 'new-password'
也可以使用之前配置好的/etc/init.d/mysql來(lái)啟動(dòng),然后修改密碼
service mysql start
也可以在啟動(dòng)后使用mysql_secure_installation 來(lái)修改密碼
這些命令大部分都在mysql的安裝目錄,按需使用即可.
檢查
檢查是否可以連接
/app/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.4-m7 Source distribution
Copyright (c) 2000, 2011, 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>
trouble-shooting
1.編譯php使用mysql的時(shí)候報(bào)錯(cuò)
/app/soft/php-5.3.28/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] 錯(cuò)誤 127
Generating phar.phar
/app/soft/php-5.3.28/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.phar] 錯(cuò)誤 127
按照提示檢查這個(gè)文件發(fā)現(xiàn)少了庫(kù)libmysqlclient.so.18, 如提示所述確實(shí)找不到了
ldd /app/soft/php-5.3.28/sapi/cli/php
linux-vdso.so.1 => (0x00007fff0ef81000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003d28a00000)
libz.so.1 => /lib64/libz.so.1 (0x0000003d25e00000)
libedit.so.0 => /usr/lib64/libedit.so.0 (0x00000037b5800000)
libncurses.so.5 => /lib64/libncurses.so.5 (0x00000037b7000000)
libmysqlclient.so.18 => not found
libgmp.so.3 => /usr/lib64/libgmp.so.3 (0x0000003d03800000)
libbz2.so.1 => /lib64/libbz2.so.1 (0x0000003d2a200000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x000000376e000000)
librt.so.1 => /lib64/librt.so.1 (0x0000003d26200000)
libm.so.6 => /lib64/libm.so.6 (0x0000003d26600000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003d25200000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x0000003774000000)
libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x0000003dc3e00000)
libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003d03400000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003d03000000)
libc.so.6 => /lib64/libc.so.6 (0x0000003d25600000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003d27200000)
libfreebl3.so => /usr/lib64/libfreebl3.so (0x0000003d28600000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003d2ca00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003d25a00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003d24e00000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003d2c600000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x0000003d2a600000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0000003d29200000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003d2ae00000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003d2b200000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003d2aa00000)
最后多方檢查發(fā)現(xiàn),這個(gè)庫(kù)是必須存在于/lib64或者/usr/lib64的,無(wú)法通過(guò)配置文件編譯改變位置,而mysql 5.5 后會(huì)將這個(gè)庫(kù)生成在安裝目錄里面,所以做了一個(gè)軟連接,將他們溝通起來(lái)
ln -s /app/mysql564/lib/* /lib64/
2.mysql 5.5 啟動(dòng)時(shí)候報(bào)錯(cuò)
MySql server startup error 'The server quit without updating PID file
google了很多發(fā)現(xiàn)5.5都有這個(gè)問(wèn)題,5.6卻沒(méi)有
參考:http://stackoverflow.com/questions/4963171/mysql-server-startup-error-the-server-quit-without-updating-pid-file/25683395#25683395 發(fā)現(xiàn)有很多解決辦法沃暗,不過(guò)對(duì)于我的問(wèn)題并沒(méi)有作用月洛,最后發(fā)現(xiàn)mysql文檔有提到這個(gè)http://dev.mysql.com/doc/refman/5.6/en/charset-server.html,當(dāng)然我也補(bǔ)充到里面去了孽锥。
在my.cnf里面加入?yún)?shù)
skip-character-set-client-handshake
collation_server=utf8_unicode_ci
character_set_server=utf8
原文引用:http://www.godblessyuan.com/2015/01/18/mysql5-5_mysql5-6_make_install/