微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

How to install MySQL 5.7 on CentOS 7.3

基于centos 7的mysql 5.7自动化安装,这里顺便说一下my.cnf里的一些定义的参数
比如下面两个
innodb_buffer_pool_dump_at_shutdown=1 #关闭时把热数据dump到本地磁盘
innodb_buffer_pool_load_at_startup=1  #启动时把热数据加载到内存

因为MysqL重启时候会面临一个问题,就是如何将之前频繁访问的数据重新加载回Buffer中,
也就是说如何对InnoDB Buffer Pool进行预热来快速恢复之前的性能状态。

增加了undo log的自定义目录,因为把undo log从共享表空间ibdata1里拆分出去的话,需要
在my.cnf里提前指定好,不然等数据库启动好后再指定会报错。
innodb_undo_log_truncate=1 #开启在线回收
innodb_max_undo_los_size=1G #这个就是阈值(认是1GB)时,会触发truncate回收动作。

然后说一下,下面这个配置
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
因为ibtmp1文件是 MysqL5.7的新特性,MysqL5.7使用了独立的临时表空间来存储临时表数据,
初始化12M,且认无上限,我这里设定了最高不能超过5g,释放这个临时表空间唯一的办法就
是启数据库。

innodb_read_io_threads, innodb_write_io_threads: 文件读写的 I/O 线程数
可根据并发量和 cpu 核心数适当调整

也不要再去纠结
query_cache_size和query_cache_type这两个参数了,这对于MysqL来说就是鸡肋
而且认就是关闭的,建议采用认值,也就是设置为0,关闭

Redo logs 记录了所有的数据变更
恢复时间不再是一个问题
innodb_log_file_size = 2047M before 5.6
innodb_log_file_size>= 2047M from 5.6  
So ... 越大系统性能更稳定

这个大家应该都知道
innodb_buffer_pool_size
你懂的,自己物理内存大小的50~70%

最后还有一点,新版的MysqL认监听在IPv6上,记得关闭掉它
bind-address=0.0.0.0

当MysqL 数据库发生死锁时, innodb status 里面会记录最后一次死锁的相关信息,但MysqL 错误日志里面

不会记录死锁相关信息,要想记录,启动 innodb_print_all_deadlocks  参数 。

当系统并发很高时,很多的线程等待同一个行锁,死锁检测可能会拖慢系统,这个时候关闭死锁检测可能更好

innodb_print_all_deadlocks = 1

最后说一句:MysqL认的隔离级别不适合大部分的应用场景,而且容易发生死锁,所以我这里改成了read-committed

好了,最后就是安装步骤了,其实都已经脚本化了。

mkdir -p /home/tools
cd /home/tools
yum -y install numactl libaio
wget http://god.nongdingbang.net/downloads/MysqL-5.7-el7.tgz && tar zxvf MysqL-5.7-el7.tgz
if [ $? -eq 0 ];then
rpm -Uvh MysqL*.rpm
fi
mkdir -p /data/{MysqL_data,MysqL_log,MysqL_slow,MysqL_undo}
chown -R MysqL.MysqL /data/*
cat >/etc/my.cnf<<EOF
[client]
port=3306
socket=/tmp/MysqL.sock
[MysqL]
no-auto-rehash
[MysqLd]
port=3306
character-set-server=utf8
socket=/tmp/MysqL.sock
datadir=/data/MysqL_data
explicit_defaults_for_timestamp=true
lower_case_table_names=1
sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
bind-address=0.0.0.0
back_log=103
max_connections=500
max_connect_errors=100000
table_open_cache=512
external-locking=FALSE
max_allowed_packet=128M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=51
query_cache_size=0
query_cache_type=0
#query_cache_limit=4M
transaction_isolation=READ-COMMITTED
tmp_table_size=96M
max_heap_table_size=96M
log-error=/data/MysqL_log/error.log
###***slowqueryparameters
long_query_time=2
slow_query_log=1
slow_query_log_file=/data/MysqL_slow/slow.log
###***binlogparameters
log-bin=/data/MysqL_log/MysqL-bin
binlog_cache_size=1M
max_binlog_cache_size=4096M
max_binlog_size=1024M
binlog_format=ROW
binlog_row_image=full
expire_logs_days=3
sync_binlog=0
###***undolog
innodb_undo_directory=/data/MysqL_undo
innodb_undo_logs=128
innodb_undo_tablespaces=4
innodb_undo_log_truncate=1
innodb_max_undo_log_size=1G
innodb_purge_rseg_truncate_frequency
#***MyISAMparameters
key_buffer_size=16M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=1M
###***master-slavereplicationparameters
server-id=1
#read-only=1
#replicate-wild-ignore-table=MysqL.%
###***Multi-Threaded Slave
#slave-parallel-type=LOGICAL_CLOCK
#slave-parallel-workers=16
#master_info_repository=TABLE
#relay_log_info_repository=TABLE
relay_log_recovery=ON
#***Innodbstorageengineparameters
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
innodb_buffer_pool_size=16G
innodb_data_file_path=ibdata1:10M:autoextend
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
#innodb_file_io_threads=8
innodb_thread_concurrency=0
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=16M
innodb_log_file_size=2048M
innodb_log_files_in_group=2
innodb_max_dirty_pages_pct=75
innodb_buffer_pool_dump_pct=50
innodb_lock_wait_timeout=50
innodb_file_per_table=on
innodb_flush_neighbors=0
innodb_flush_method=O_DIRECT
innodb_read_io_threads=16
innodb_write_io_threads=16
innodb_io_capacity = 5000
#innodb_print_all_deadlocks = 1
wait_timeout = 14400
interactive_timeout = 14400
[MysqLdump]
quick
max_allowed_packet=128M
 
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
 
[MysqLd_safe]
open-files-limit=28192
log-error=/data/MysqL_log/error.log
pid-file=/data/MysqL_data/MysqLd.pid
EOF

## Initialize MysqL configuration
MysqLd --defaults-file=/etc/my.cnf --user=MysqL \
--datadir=/data/MysqL_data --initialize-insecure

## Start MysqL
systemctl restart MysqLd && systemctl enable MysqLd

## Setting root's password for MysqL
##############################################
read -s -p "Enter password : " password
MysqL -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '"$password"';"
MysqL -uroot -p"$password" -DMysqL -e "select user,host,authentication_string,password_expired from user;"
MysqL -uroot -p"$password" -e "flush privileges;"

echo Your password is "$password"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐