编译安装MySQL5.5

为什么写这篇文章?

        近来在几个MySQL技术交流群里来,依然有很多的朋友不知如何编译安装MySQL,也不知道如何在一台机器如何启动多个实例,而且网上的各种编译安装也是不全完整,基于这样的原因,写下这篇文章,希望对那些热爱MySQL,还纠结在编译安装MySQL的朋友一些帮助!


安装版本:MySQL 5.5.9

操作系统版本:centos 6.4 64bit


安装步骤:

1.创建MySQL用户

  /usr/sbin/useradd mysql

2.创建必要的目录 

  mkdir -p /data/mysql_3306 (数据目录,建议用端口去区分,便于管理)

  mkdir -p /data/mysql_3306_log(存放错误日志,慢日志)

  mkdir -p /data/mysql_3306_binlog(存放binlog)

 chown -R mysql.mysql /data/mysql_3306*  (将三个目录的属主改为mysql用户)


 

3.依赖包安装

ubuntu:

aptitude install -y  cmake gcc Dialog  libncurses5-dev bison make g++ 
apt-get install  -y  libxml-parser-perl libdbd-mysql-perl 
apt-get install  -y  libglib2.0-dev libmysqlclient15-dev zlib1g-dev libpcre3-dev cmake automake libtool 

centos:

yum -y install perl-XML-Parser perl-DBI
yum install -y  cmake gcc Dialog libncurses5-dev bison make g++ automake libtool
yum install -y  glib2-devel mysql-devel zlib-devel pcre-devel


4.编译安装

tar -xvf mysql-5.5.9.tar.gz

cd mysql-5.5.9

cmake . -DCMAKE_BUILD_TYPE:STRING=Release \
                -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql  \
-DCOMMUNITY_BUILD:BOOL=ON \
-DENABLED_PROFILING:BOOL=ON \
-DENABLE_DEBUG_SYNC:BOOL=OFF \
-DINSTALL_LAYOUT:STRING=STANDALONE \
-DMYSQL_MAINTAINER_MODE:BOOL=OFF \
-DWITH_EMBEDDED_SERVER:BOOL=ON \
-DDEFAULT_CHARSET=utf8 \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_SSL:STRING=bundled \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled  \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-LH 

make -j8 


make install


至此没有报错,MySQL已编译安装,接下来启动MySQL了。。


5.创建MySQL字典信息

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql_3306 --user=mysql & 


6.以守护进程的方式开启MySQL(启动的时候只需将我下文的举例my.cnf拷贝到/data/mysql_3306下以以下的命令启动即可)


sudo /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql_3306/my.cnf &



附my.cnf 

[client]
port            = 3306 
socket          = /data/mysql_3306/mysql_3306.sock




[mysqld]




port            = 3306
socket          = /data/mysql_3306/mysql_3306.sock
pid-file        = /data/mysql_3306/mysql_3306.pid
datadir=/data/mysql_3306
tmpdir=/data/mysql_3306


#charset
character-set-server=utf8
key_buffer_size = 2G
max_allowed_packet = 128M
table_open_cache = 2000
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 2000
thread_concurrency = 64
max_heap_table_size     = 128M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 2G
myisam_repair_threads = 1
myisam_recover




#connect
max_connections         = 2000
max_connect_errors=999999
slow_launch_time=1
skip-name-resolve


#log
log-error=/data/mysql_3306_log/error.log
general_log_file=/data/mysql_3306_log/general_log.log
binlog_format=row
log_bin                 = /data/mysql_3306_binlog/mysql-bin.log
relay_log               = /data/mysql_3306_binlog/mysql-relay-bin.log
max_binlog_size         = 100M
log_slave_updates
expire_logs_days        = 7
slow_query_log_file=/data/mysql_3306_log/slow.log
slow_query_log=on
long_query_time=1


#slave
server-id       =  13354
#skip_slave_start
slave-skip-errors=1062
replicate_ignore_db=mysql
replicate_wild_ignore_table=mysql.%
#auto_increment_offset = 1
#auto_increment_increment = 2 


#corefile
core-file


#innodb
innodb_data_home_dir = /data/mysql_3306
innodb_data_file_path = ibdata1:100M:autoextend
innodb_log_group_home_dir = /data/mysql_3306
innodb_buffer_pool_size = 2G
innodb_additional_mem_pool_size = 8M
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 0
#innodb_lock_wait_timeout = 50
innodb_log_files_in_group=4
innodb_max_dirty_pages_pct = 90
innodb_open_files=2000
innodb_doublewrite=1
innodb_file_per_table
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_thread_concurrency=16
innodb_purge_threads=1






[mysqldump]
quick
max_allowed_packet = 16M


[mysql]
auto-rehash


[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M


[mysqlhotcopy]
interactive-timeout


7.由于MySQL默认root用户是没有密码的,为了安全起见,应清除空账号和给root用户加上密码!


PS:起多个实例只需要建相应的端口目录,日志目录,将配置文件3306替换其他端口,以同样的方式初始化和启动即可!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值