源码编译安装MySQL5.6.10最佳实践_MySQL
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
文章原来放在这儿:http://wenku.baidu.com/view/95063fe3b8f67c1cfad6b8fd?fr=prin,今天看有很多浏览量了,之前忙没空整理,今天移到csdn,希望能与更多的人分享!
bitsCN.com上一篇: 为什么子类无法继承父类?