温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

How to install MySQL 5.7 on CentOS 7.3

发布时间:2020-06-09 07:05:57 来源:网络 阅读:904 作者:jinyan2049 栏目:MySQL数据库
基于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"


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI