Mysql5.6编译安装文档

1、添加mysql用户

chattr -i /etc/gshadow  /etc/shadow /etc/passwd /etc/group /etc/gshadow-  /etc/shadow- /etc/passwd- /etc/group-

groupadd mysql
useradd -r -g mysql mysql

chattr +i /etc/gshadow  /etc/shadow /etc/passwd /etc/group /etc/gshadow-  /etc/shadow- /etc/passwd- /etc/group-

2、安装依赖包

yum -y install gcc gcc-c++  cmake perl-DBD-MySQL perl-DBI bison-devel ncurses-devel openssl-devel glibc readline-devel openssl openssl-devel ncurses ncurses-devel jemalloc-devel jemalloc

3、安装源码包

wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.41.tar.gz

tar -zxvf mysql-5.6.41.tar.gz 

cd mysql-5.6.41

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost_1_59_0  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1  -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_DEBUG=0 -DWITH_EMBEDDED_SERVER=0 -DMYSQL_USER=mysql

cpu_num=`cat /proc/cpuinfo | grep processor | wc -l`

make -j $cpu_num

make install

注意:编译完成后,所有的mysql相关文件都存放在/usr/local/mysql目录下



##my.cnf配置文件
vim /etc/my.cnf
####Tunning 
[client]
port            = 3306
socket          = /data/mysql/mysql.sock


[mysqld]
port            = 3306
socket          = /data/mysql/mysql.sock
basedir         = /usr/local/mysql
datadir         = /data/mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#### Network####
connect_timeout  = 60
wait_timeout     = 28800
max_connections  = 4096
max_allowed_packet  = 64M
max_connect_errors = 1000
wait_timeout=600
skip-name-resolve
max_prepared_stmt_count=1000000

### For semi_sync####
#rpl_semi_sync_master_enabled = 1 
#rpl_semi_sync_master_timeout = 3000 # 1 second


#### limits####
tmp_table_size      = 512M
max_heap_table_size = 256M
#table_cache         = 512
query_cache_limit   = 1M
query_cache_size    = 128M
join_buffer_size    = 256k
read_buffer_size    = 256k
read_rnd_buffer_size= 512k

skip-external-locking
key_buffer_size         = 128M
table_open_cache        = 4096
sort_buffer_size        = 512K
net_buffer_length       = 8K
myisam_sort_buffer_size = 8M
thread_concurrency              = 64
thread_cache_size               =32

#### logs####
log_error                       = /var/log/mysql/mysql-error.log
slow_query_log_file             = /var/log/mysql/mysql-slow.log
slow_query_log                  = 1
long_query_time                 = 2
binlog_format                   = mixed
log-bin                         = mysql-bin
expire_logs_days                = 5
relay-log                        = relay-log
log-slave-updates


#### replicate###
server-id                       = 6
replicate-ignore-db             = mysql,information_schema 
sync_binlog                     = 1


#### innodb####
innodb_data_home_dir            = /data/mysql
innodb_log_group_home_dir               = /data/mysql
innodb_file_per_table           = 1
innodb_status_file              = 1
innodb_additional_mem_pool_size = 128M

#%70~80% physical memory
innodb_buffer_pool_size         = 32G
innodb_flush_method             = O_DIRECT
innodb_flush_log_at_trx_commit  = 1
innodb_support_xa               = 1
innodb_lock_wait_timeout        = 50
innodb_data_file_path = ibdata1:128M:autoextend
innodb_log_buffer_size = 128M
innodb_log_file_size = 512M



[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

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

[mysqlhotcopy]
interactive-timeout

4、配置mysql启动脚本

###配置myql随机启动
cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld 
sed -i 's#basedir=$#basedir=/usr/local/mysql#g' /etc/init.d/mysqld
sed -i 's#datadir=$#datadir=/data/mysql#g' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

5、配置执行文件路径

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

6、初始化mysql

mkdir -p /data/mysql/

ln -s /data/mysql/ /usr/local/mysql/data

chown -R mysql:mysql /data/mysql/

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

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

7、启动mysql

/etc/init.d/mysqld start
/etc/init.d/mysqld stop
chkconfig mysqld on

你可能感兴趣的:(mysql5.6)