MySQL 源码 CMake 编译部署

运维的坑 2017-03-20 08:57 暂无评论

随手记一下。

MySQL 源码编译选项参考 MySQL 官方文档:https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

1. 首先安装一下需要的依赖

yum install -y vim wget cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl perl perl-Data-Dumper

2. 把源码包下载下来

wget -c https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz && tar zxf mysql-5.6.35.tar.gz && cd mysql-5.6.35

3. 创建用户及组

groupadd mysql && useradd mysql -g mysql -M -s /sbin/nologin

4. 编译安装

cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNODB_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_LOCAL_INIFILE=1 \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1

编译安装

make && make install

5. 赋予目录权限

chown mysql:mysql /usr/local/mysql -R

6. 初始化数据库

./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --ldata=/usr/local/mysql/data --defaults-file=/etc/my.cnf --user=mysql

启动数据库

./bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-kill-mysqld --user=mysql

附:(my.cnf)参考

[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8

[mysql]
pid_file=/tmp/mysqld.pid

[mysqld]
server_id=101
port=3306
socket=/tmp/mysql.sock
pid_file=/tmp/mysqld.pid
tmpdir=/tmp/

autocommit=1
general_log=off
explicit_defaults_for_timestamp=true
character_set_server=utf8

# system
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_allowed_packet=1g
max_connections=3000
max_user_connections=2800
open_files_limit=65535
skip_name_resolve=ON

#binlog
log_bin=/usr/local/mysql/logs/binlog
binlog_cache_size=32768
binlog_format=row
expire_logs_days=7
log_slave_updates=ON
max_binlog_cache_size=2147483648
max_binlog_size=524288000
sync_binlog=100

#logging
log_error=/usr/local/mysql/logs/error.log
slow_query_log_file=/usr/local/mysql/logs/3306/slow.log
log_queries_not_using_indexes=0
slow_query_log=1
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1

#relay
relay_log=/usr/local/mysql/logs/relaylog
relay_log_index=/usr/local/mysql/logs/relay.index
relay_log_info_file=/usr/local/mysql/logs/relay-log.info

#slave
slave_load_tmpdir=/tmp
slave_skip_errors=OFF


#innodb
innodb_data_home_dir=/usr/local/mysql/logs/iblog
innodb_log_group_home_dir=/usr/local/mysql/logs/iblog
innodb_adaptive_flushing=ON
innodb_adaptive_hash_index=ON
innodb_autoinc_lock_mode=1
innodb_buffer_pool_instances=8

#default
innodb_change_buffering=inserts
innodb_checksums=ON
innodb_buffer_pool_size= 128M
innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend
innodb_doublewrite=ON
innodb_file_format=Barracuda
innodb_file_per_table=ON
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_io_capacity=1000
innodb_lock_wait_timeout=10
innodb_log_buffer_size=67108864
innodb_log_file_size=1048576000
innodb_log_files_in_group=4
innodb_max_dirty_pages_pct=60
innodb_open_files=60000
innodb_purge_threads=1
innodb_read_io_threads=4
innodb_stats_on_metadata=OFF
innodb_support_xa=ON
innodb_use_native_aio=OFF
innodb_write_io_threads=10

[mysqld_safe]
datadir=/usr/local/mysql/data
暂无评论