CentOS6.5_64bit下编译安装MySQL-5.6.23

时间:2022-06-24 17:57:20

转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/44785511

************************************************************
         CentOS6.5_64bit下编译安装MySQL-5.6.23 
**************************************************************

一、关闭防火墙
chkconfig iptables off 
service iptables stop

二、下载mysql源代码包。mysql-5.6.23.tar.gz 
下载时注意别选成其它的linux安装包。不然编译肯定报错。选择平台的下拉列表里选择 Source Code,Select Platform: Source Code ,
下载 Generic Linux (Architecture Independent), Compressed TAR Archive。

三、加入用户和组:
groupadd  mysql #添加用户组
useradd -g mysql mysql -s /usr/sbin/nologin

四、创建文件夹及授权
mkdir -p /u01/my3306/data            #mysql数据文件夹
mkdir -p /u01/my3306/log/iblog            #mysql innodb日志
mkdir -p /u01/my3306/log/binlog           #mysql日志
mkdir -p /u01/my3306/log/relaylog
mkdir -p /u01/my3306/run
mkdir -p /u01/my3306/tmp
chown -R mysql:mysql /u01/my3306
chmod -R 755 /u01/my3306

五、解压
tar -zxvf mysql-5.6.23.tar.gz 
cd mysql-5.6.23

六、编译并安装
cmake \
-DCMAKE_INSTALL_PREFIX=/u01/my3306 \
-DINSTALL_DATADIR=/u01/my3306/data  \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_SSL=yes \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DSYSCONFDIR=/etc \
-DWITH_READLINE=on

make
make install

七、改动配置文件my.cnf參数
cp /u01/my3306/support-files/my-default.cnf  /u01/my3306/my.cnf

vi   /u01/my3306/my.cnf   ---加入

[client]
port = 3306
socket =/u01/my3306/run/mysql.sock

[mysql]
no-auto-rehash
pid_file=/u01/my3306/run/mysqld.pid

[mysqld]
## disable autocommit
autocommit=0
general_log=off
explicit_defaults_for_timestamp=true

# system
basedir=/u01/my3306
datadir=/u01/my3306/data/
max_allowed_packet=134217728
max_connections=8192
max_user_connections=8000
open_files_limit=65535
pid_file=/u01/my3306/run/mysqld.pid
port=3306
server_id=1
skip_name_resolve=ON
socket=/u01/my3306/run/mysql.sock
tmpdir=/u01/my3306/tmp

# binlog
binlog_cache_size=32768
binlog_format=row
expire_logs_days=7
log_bin=/u01/my3306/log/binlog
log_slave_updates=ON
max_binlog_cache_size=2147483648
max_binlog_size=524288000
sync_binlog=100

#relay
relay_log=/u01/my3306/log/relaylog
relay_log_index=/u01/my3306/log/relay.index
relay_log_info_file=/u01/my3306/log/relay-log.info

# LOGGING #
log_error                      = /u01/my3306/log/alert.log
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /u01/my3306/log/slow.log
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1

#slave#
slave_skip_errors=OFF
log_slave_updates=ON

# innodb #
innodb_log_group_home_dir=/u01/my3306/log/iblog
innodb_data_home_dir=/u01/my3306/log/iblog
innodb_adaptive_flushing=1
innodb_additional_mem_pool_size=20M
innodb_buffer_pool_instances=8
innodb_change_buffering=inserts
innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 4
innodb_log_file_size           = 32M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 128M
innodb_file_format=Barracuda
innodb_file_io_threads=4
innodb_flush_neighbors=0
innodb_io_capacity=200
innodb_lock_wait_timeout=5
innodb_log_buffer_size=64M
innodb_lru_scan_depth=2048
innodb_max_dirty_pages_pct=60
innodb_old_blocks_time=1000
innodb_online_alter_log_max_size=200M
innodb_open_files=200
innodb_print_all_deadlocks=1
innodb_purge_threads=4
innodb_read_ahead_threshold=0
innodb_read_io_threads=8
innodb_rollback_on_timeout=0
innodb_sort_buffer_size=2M
innodb_spin_wait_delay=6
innodb_stats_on_metadata=0
innodb_strict_mode=1
innodb_sync_array_size=256
innodb_sync_spin_loops=30
innodb_thread_concurrency=64
innodb_use_native_aio=0
innodb_write_io_threads=8
innodb_support_xa=1

[mysqld_safe]
datadir=/u01/my3306/data/

八、运行MySQL安装脚本
./scripts/mysql_install_db  --defaults-file=/u01/my3306/my.cnf  --user=mysql --datadir=/u01/my3306/data
    
说明:defaults-file表示指定默认的配置文件,假设不指定。系统默认的优先级是先使用/etc/my.cnf作为mysql的配置文件,那之前make的那些參数就白设置了.

九、启动mysql
mysqld_safe --defaults-file=/u01/app/mysql/data/mysql3306/my.cnf --user=mysql &

十、登录MySQL
mysql -h127.0.0.1 -uroot -P3306