您好,欢迎访问一九零五行业门户网

源码编译安装MySQL5.6.10最佳实践_MySQL

bitscn.com 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__storage_engine也不是-dwithout__storage_engine 来指定存储引擎,该存储引擎将安装成共享模块式的。如果不是共享模块式的将排除在外。共享模块安装时必须使用install plugin语句或--plugin-load才可以使用。
有关插件的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 theenable-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_port=,
# master_user=,master_password= ;
#
# where you replace ,, by quoted strings and
# by the master's port number(3306 by default).
#
# 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
其它类似信息

推荐信息