update mysql's script and configuration

pull/11/head
Zhang Peng 2019-11-27 13:34:49 +08:00
parent b24c6a928a
commit b526a167c4
2 changed files with 53 additions and 43 deletions

View File

@ -1,45 +1,48 @@
[mysqld]
# mysql 的数据目录
datadir = /var/lib/mysql
# binlog 目录
log_bin = /var/lib/mysql/binlog
# socket 文件
socket = /var/lib/mysql/mysql.sock
# 设置时区
default-time_zone = '+8:00'
# 数据库默认字符集
character-set-server = utf8mb4
# 数据库字符集对应一些排序等规则,注意要和 character-set-server 对应
collation-server = utf8mb4_0900_ai_ci
# 数据库连接相关设置
# -------------------------------------------------------------------------------
# 最大连接数
# Mysql 基本配置模板
# -------------------------------------------------------------------------------
[mysqld]
# GENERAL
# -------------------------------------------------------------------------------
server_id = 2
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
pid_file = /var/lib/mysql/mysql.pid
user = mysql
port = 3306
default_storage_engine = InnoDB
default_time_zone = '+8:00'
character_set_server = utf8mb4
collation_server = utf8mb4_0900_ai_ci
# LOG
# -------------------------------------------------------------------------------
log_error = /var/log/mysql/mysql-error.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 3
min_examined_row_limit = 100
expire_logs_days = 7
# InnoDB
# -------------------------------------------------------------------------------
innodb_buffer_pool_size = 4G
innodb_log_file_size = 128M
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
# MyIsam
# -------------------------------------------------------------------------------
key_buffer_size = 256M
# OTHER
# -------------------------------------------------------------------------------
tmp_table_size = 32M
max_heap_table_size = 32M
max_connections = 10000
# 最大错误连接数
max_connect_errors = 10000
# MySQL打开的文件描述符限制
open_files_limit = 65535
# 日志文件相关设置,一般只开启三种日志,错误日志,慢查询日志,二进制日志。普通查询日志不开启。
# -------------------------------------------------------------------------------
# 错误日志记录的信息
log_error_verbosity = 2
# 错误日志文件地址
log-error = /var/log/mysqld.log
# 开启慢查询
slow_query_log = 1
# 开启慢查询时间此处为3秒达到此值才记录数据
long_query_time = 3
# 检索行数达到此数值,才记录慢查询日志中
min_examined_row_limit = 10
# 慢查询日志文件地址
slow-query-log-file = /var/log/mysqld-slow.log
# 开启记录没有使用索引查询语句
log_queries_not_using_indexes = 1
# mysql清除过期日志的时间默认值0不自动清理而是使用滚动循环的方式。这里设置为30天
binlog_expire_logs_seconds = 2592000
# 如果二进制日志写入的内容超出给定值日志就会发生滚动。你不能将该变量设置为大于1GB或小于4096字节。 默认值是1GB。
max_binlog_size = 1000M
[client]
socket = /var/lib/mysql/mysql.sock
port = 3306

View File

@ -49,8 +49,10 @@ printf "${CYAN}>>>> replace settings${RESET}\n"
cp /etc/my.cnf /etc/my.cnf.bak
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/mysql/my.cnf -O /etc/my.cnf
# 创建空的慢查询日志文件
touch /var/log/mysqld-slow.log
chmod 777 /var/log/mysqld-slow.log
mkdir -p /var/log/mysql
touch /var/log/mysql/mysql-slow.log
chmod 777 /var/log/mysql/mysql-slow.log
chown -R mysql:mysql /var/log/mysql
# 设置开机启动
printf "${CYAN}>>>> start mysqld${RESET}\n"
@ -58,6 +60,11 @@ systemctl enable mysqld
systemctl start mysqld
systemctl daemon-reload
cat >> /etc/security/limits.conf << EOF
mysql soft nofile 65536
mysql hard nofile 65536
EOF
password=$(grep "password" /var/log/mysqld.log | awk '{print $NF}')
printf "临时密码为:${PURPLE}${password}${RESET},请登录 mysql 后重置新密码\n"