1安裝cmake
MySQL從5.5版本開始,通過./configure進行編譯配置方式已經被取消,取而代之的是cmake工具。
因此,我們首先要在系統中源碼編譯安裝cmake工具。
# wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
# tar zxvf cmake-2.8.7.tar.gz
# cd cmake-2.8.7
# ./configure
# make
# make install
1.1cmake命令語法
1.2重新編譯時,需要清除舊的對象文件和緩存信息
# make clean
# rm -f CMakeCache.txt
1.3安裝選項
CMAKE_INSTALL_PREFIX值是安裝的基本目錄,其他cmake選項值是不包括前綴,是相對路徑名,絕對路徑包括CMAKE_INSTALL_PREFIX路徑。如-DINSTALL_SBINDIR=sbin的絕對路徑是/usr/local/mysql /sbin
1.4存儲引擎選項
mysql存儲引擎是插件式的,因此插件控制選項可以指定那個存儲引擎安裝。
configure編譯插件選項--with-plugins=csv,myisam,myisammrg,heap,innobase,archive,blackhole在cmake中沒有直接對應的相同選項。對於csv,myisam,myisammrg,heap在cmake中是不需要明確指定存儲引擎的名稱,因為它們是強制性安裝。
可以使用以下選擇來安裝innodb,archive,blackhole存儲引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
(1可以使用on代替)
如果既不是-DWITH_
有關插件的CMake的選項的其他信息,請查閱: http://forge.mysql.com/wiki/MySQL_Internals_Support_for_Plug-Ins
1.5 lib庫選項
1.6其他選項
之前MySQL的編譯選項大多數都支持。新舊版本之間的安裝選項映射成大寫字母,刪除選項前面破折號,中間字符間的破折號替換成下劃線。如:
--with-debug => WITH_DEBUG=1
--with-embedded-server => WITH_EMBEDDED_SERVER
1.7調試配置過程
使用configure編譯完將生成config.log和config.status文件。
使用cmake編譯完在CMakeFiles目錄下生成CMakeError.log 和CMakeOutput.log文件。
1.8第三方接口工具
在之前的版本,第三方工具從MySQL頂層源目錄中讀取源configure.in文件來確定mysql版本。如:對5.5.7 - RC版本的AC_INIT線看起來像這樣:
AC_INIT([MySQLServer], [5.5.7-rc], [], [mysql])
現在的版本可以直接讀取版本文件。如:如果版本是5.5.8,文件看起來像這樣的:
MYSQL_VERSION_MAJOR=5
MYSQL_VERSION_MINOR=5
MYSQL_VERSION_PATCH=8
MYSQL_VERSION_EXTRA=rc
如果源碼包不是GA版,MYSQL_VERSION_EXTRA的值將非空。如:對於一個發布RC版本是這樣的: MYSQL_VERSION_EXTRA=rc
構建5位數字的版本號,使用下面公式:
MYSQL_VERSION_MAJOR*10000+ MYSQL_VERSION_MINOR*100 + MYSQL_VERSION_PATCH
2驗證安裝依賴
通過 rpm -qa | grep name的方式驗證以下軟件包是否已全部安裝。
gcc* gcc-c++* autoconf* automake* zlib*libxml* ncurses-devel* libmcrypt* libtool*
通過yum安裝示例
例:yum install gcc gcc-c++
例:yum install ncurses-devel
如果缺少相關的軟件包,可通過yum -y install的方式在線安裝,或直接從系統安裝光盤中找到並通過rpm -ivh的方式安裝。
3安裝前的系統設置
建立mysql安裝目錄及數據存放目錄
# mkdir /usr/mysql5.5
# mkdir /usr/mysql5.5/data
創建用戶和用戶組
# groupadd mysql
# useradd –gmysql mysql
賦予數據存放目錄權限
# chown mysql:mysql –R /opt/mysql5.5/data
4正式開始安裝(從configure更換為cmake)
我相信大多數人都已經習慣了之前的configure方式,並且所使用的參數也是比較個性化的,換成cmake之後,這一方面會帶來不少的麻煩。
還好,MySQL的官方網站提供了二者的參數對照表,我們可以盡可能的保留之前的參數,來編譯配置新的MySQL版本。
configure 與cmake參數對照指南:
http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide
以我自己為例,之前我一直使用的參數為:
./configure --prefix=/opt/mysql/
--sysconfdir=/opt/mysql/etc
--localstatedir=/opt/mysql/data
--with-tcp-port=3306
--with-unix-socket-path=/tmp/mysqld.sock
--with-mysqld-user=mysql
--enable-assembler
--with-extra-charsets=all
--enable-thread-safe-client
--with-big-tables
--with-readline
--with-ssl
--with-embedded-server
--enable-local-infile
--with-plugins=partition,innobase,myisammrg
經過與cmake的參數對照之後,去除掉已經被取消的參數(大多數是因為新版本已經默認啟用),cmake的參數配置如下:
cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql
-DSYSCONFDIR=/opt/mysql/etc
-DMYSQL_DATADIR=/opt/mysql/data
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock
-DMYSQL_USER=mysql
-DEXTRA_CHARSETS=all
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_EMBEDDED_SERVER=1
-DENABLED_LOCAL_INFILE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
不帶換行符的(只有一行)
4.1參數:-DWITHOUT_PARTITION_STORAGE_ENGINE=1
在64位機器上編譯不過,會出現如下錯誤:(64位機器的浮點數運算上出錯,導致找不著相應的函數)
libsql.a(handler.cc.o): In function`get_ha_partition(partition_info*)’:
/data/mysql-5.5.14/sql/handler.cc:269: undefined reference to`ha_partition::ha_partition(handlerton*, partition_info*)’
/data/mysql-5.5.14/sql/handler.cc:271: undefined reference to`ha_partition::initialize_partition(st_mem_root*)’
libsql.a(sql_partition_admin.cc.o): In function`Alter_table_truncate_partition_statement::execute(THD*)’:
/data/mysql-5.5.14/sql/sql_partition_admin.cc:165: undefinedreference to `ha_partition::truncate_partition(Alter_info*, bool*)’
collect2: ld returned 1 exit status
make[2]: *** [sql/mysqld] Error 1
make[1]: *** [sql/CMakeFiles/mysqld.dir/all] Error 2
make: *** [all] Error 2
4.2參數:-DWITH_SSL=bundled
自mysql5.6.*及以後的版本都要默認帶上此參數,否則編譯不過 ,相關貼子:
https://github.com/santisaez/powerstack/issues/49
Use bundled SSL on CentOS-5
4.3安裝執行
# tar xvf mysql-5.5.10.tar.gz
# cd mysql-5.5.10
# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.5 -DSYSCONFDIR=/usr/local/mysql5.5/etc-DMYSQL_DATADIR=/usr/local/mysql5.5/data -DMYSQL_TCP_PORT=3306-DMYSQL_UNIX_ADDR=/usr/local/mysql5.5/mysqld.sock -DMYSQL_USER=mysql-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all-DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1-DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_SSL=bundled
#make
#make install
5 設置
#cd support-files/
拷貝配置文件:
#cp my-default.cnf /etc/my.cnf
設置開機自動啟動
#cp mysql.server /etc/rc.d/init.d/mysqld
5.1初始化數據庫
#/usr/local/mysql5.5/scripts/mysql_install_db--defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.5--datadir=/usr/local/mysql5.5data --user=mysql
5.2設置
#vi /etc/init.d/mysqld(編輯此文件,查找並修改以下變量內容:)
basedir=/usr/local/mysql5.5
datadir=/var/mysql5.5/data
加入啟動項:
#chkconfig --add mysqld
#chkconfig --level 345 mysqld on
5.3啟動服務
#service mysqld start
如果文件夾:/usr/local/mysql5.5是只讀的,會報錯:
…
…
2013-04-08 11:12:45 7886 [Note] IPv6 is notavailable.
2013-04-08 11:12:45 7886 [Note] - '0.0.0.0' resolves to '0.0.0.0';
2013-04-08 11:12:45 7886 [Note] Server socketcreated on IP: '0.0.0.0'.
2013-04-08 11:12:45 7886 [ERROR] Can't startserver : Bind on unix socket: Permission denied
2013-04-08 11:12:45 7886 [ERROR] Do youalready have another mysqld server running on socket:/usr/local/mysql5.5/mysqld.sock ?
2013-04-08 11:12:45 7886 [ERROR] Aborting
…
2013-04-08 11:12:45 7886 [Note] InnoDB:Starting shutdown...
2013-04-08 11:12:47 7886 [Note] InnoDB:Shutdown completed; log sequence number 1626077
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'BLACKHOLE'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'PERFORMANCE_SCHEMA'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'ARCHIVE'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'CSV'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'MRG_MYISAM'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'MyISAM'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'MEMORY'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'sha256_password'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'mysql_old_password'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'mysql_native_password'
2013-04-08 11:12:47 7886 [Note] Shutting downplugin 'binlog'
2013-04-08 11:12:47 7886 [Note]/usr/local/mysql5.5/bin/mysqld: Shutdown complete
130408 11:12:47 mysqld_safe mysqld from pidfile /usr/local/mysql5.5/data/zskw2.pid ended
解決辦法:將/usr/local/mysql5.5設為讀寫即可
…
5.4 設置密碼
#/usr/local/mysql/bin/mysqladmin password[new-password]
6數據庫初始化
如果想讓數據庫可遠程訪問,必須在庫中mysql下的user裡存在如下用戶
Host user password
% root xxx
7附錄
7.1參考網址
http://www.centos.bz/2011/09/linux-compile-install-mysql-5-5-15-from-source/
http://blog.csdn.net/sunjingzhi/article/details/6671668
https://github.com/santisaez/powerstack/issues/49
http://heylinux.com/archives/993.html
http://www.mysqlops.com/2011/03/06/mysql_compile_reference.html
http://who0168.blog.51cto.com/253401/469898
7.2所用my.cnf
# Example MySQLconfig file for large systems.
#
# This is for a largesystem with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs lookfor option files in a set of
# locations whichdepend on the deployment platform.
# You can copy thisoption file to one of those
# locations. Forinformation about these locations, see:
#http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, youcan use all long options that a program supports.
# If you want to knowwhich options a program supports, run the program
# with the"--help" option.
# The followingoptions will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
#socket = /var/lib/mysql/mysql.sock
socket = /usr/local/mysql5.5/mysqld.sock
#character-set-server= utf8
# Here followsentries for some specific programs
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock
socket = /usr/local/mysql5.5/mysqld.sock
user=mysql
skip-external-locking
key_buffer_size =256M
max_allowed_packet =1M
table_open_cache =256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size= 4M
myisam_sort_buffer_size= 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number ofCPU's*2 for thread_concurrency
thread_concurrency =8
#character-set-server= utf8
max_connections =1000
# Don't listen on aTCP/IP port at all. This can be a security enhancement,
# if all processesthat need to connect to mysqld run on the same host.
# All interactionwith mysqld must be made via Unix sockets or named pipes.
# Note that usingthis option without enabling named pipes on Windows
# (via the"enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication MasterServer (default)
# binary logging isrequired for replication
log-bin=mysql-bin
# binary loggingformat - mixed recommended
binlog_format=mixed
# required unique idbetween 1 and 2^32 - 1
# defaults to 1 ifmaster-host is not set
# but will notfunction as a master if omitted
server-id = 1
# Replication Slave(comment out master section to use this)
#
# To configure thishost as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGEMASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=
# MASTER_USER=
#
# where you replace
#
#
# Example:
#
# CHANGE MASTER TOMASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe',MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variablesbelow. However, in case you choose this method, then
# start replication for the first time (evenunsuccessfully, for example
# if you mistyped the password inmaster-password and the slave fails to
# connect), the slave will create a master.infofile, and any later
# change in this file to the variables'values below will be ignored and
# overridden by the content of themaster.info file, unless you shutdown
# the slave server, delete master.info andrestart the slaver server.
# For that reason, you may want to leave thelines below untouched
# (commented) and instead use CHANGE MASTERTO (see above)
#
# required unique idbetween 2 and 2^32 - 1
# (and different fromthe master)
# defaults to 2 ifmaster-host is set
# but will notfunction as a slave if omitted
#server-id = 2
#
# The replicationmaster for this slave - required
#master-host =
#
# The username theslave will use for authentication when connecting
# to the master -required
#master-user =
#
# The password theslave will authenticate with when connecting to
# the master -required
#master-password=
#
# The port the masteris listening on.
# optional - defaultsto 3306
#master-port =
#
# binary logging - notrequired for slaves, but recommended
#log-bin=mysql-bin
# Uncomment thefollowing if you are using InnoDB tables
#innodb_data_home_dir= /var/lib/mysql
#innodb_data_file_path= ibdata1:10M:autoextend
#innodb_log_group_home_dir= /var/lib/mysql
# You can set.._buffer_pool_size up to 50 - 80 %
# of RAM but bewareof setting memory usage too high
#innodb_buffer_pool_size= 256M
#innodb_additional_mem_pool_size= 20M
# Set.._log_file_size to 25 % of buffer pool size
#innodb_log_file_size= 64M
#innodb_log_buffer_size= 8M
#innodb_flush_log_at_trx_commit= 1
#innodb_lock_wait_timeout= 50
[mysqldump]
quick
max_allowed_packet =16M
[mysql]
no-auto-rehash
# Remove the nextcomment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size =128M
sort_buffer_size =128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout