Skip to content

Commit b526a16

Browse files
committed
update mysql's script and configuration
1 parent b24c6a9 commit b526a16

2 files changed

Lines changed: 48 additions & 38 deletions

File tree

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
1+
# -------------------------------------------------------------------------------
2+
# Mysql 基本配置模板
3+
# -------------------------------------------------------------------------------
4+
15
[mysqld]
2-
# mysql 的数据目录
6+
# GENERAL
7+
# -------------------------------------------------------------------------------
8+
server_id = 2
39
datadir = /var/lib/mysql
4-
# binlog 目录
5-
log_bin = /var/lib/mysql/binlog
6-
# socket 文件
710
socket = /var/lib/mysql/mysql.sock
8-
# 设置时区
9-
default-time_zone = '+8:00'
10-
# 数据库默认字符集
11-
character-set-server = utf8mb4
12-
# 数据库字符集对应一些排序等规则,注意要和 character-set-server 对应
13-
collation-server = utf8mb4_0900_ai_ci
11+
pid_file = /var/lib/mysql/mysql.pid
12+
user = mysql
13+
port = 3306
14+
default_storage_engine = InnoDB
15+
default_time_zone = '+8:00'
16+
character_set_server = utf8mb4
17+
collation_server = utf8mb4_0900_ai_ci
1418

19+
# LOG
20+
# -------------------------------------------------------------------------------
21+
log_error = /var/log/mysql/mysql-error.log
22+
slow_query_log = 1
23+
slow_query_log_file = /var/log/mysql/mysql-slow.log
24+
long_query_time = 3
25+
min_examined_row_limit = 100
26+
expire_logs_days = 7
1527

16-
# 数据库连接相关设置
28+
# InnoDB
1729
# -------------------------------------------------------------------------------
18-
# 最大连接数
19-
max_connections = 10000
20-
# 最大错误连接数
21-
max_connect_errors = 10000
22-
# MySQL打开的文件描述符限制
23-
open_files_limit = 65535
30+
innodb_buffer_pool_size = 4G
31+
innodb_log_file_size = 128M
32+
innodb_file_per_table = 1
33+
innodb_flush_method = O_DIRECT
2434

35+
# MyIsam
36+
# -------------------------------------------------------------------------------
37+
key_buffer_size = 256M
2538

26-
# 日志文件相关设置,一般只开启三种日志,错误日志,慢查询日志,二进制日志。普通查询日志不开启。
39+
# OTHER
2740
# -------------------------------------------------------------------------------
28-
# 错误日志记录的信息
29-
log_error_verbosity = 2
30-
# 错误日志文件地址
31-
log-error = /var/log/mysqld.log
32-
# 开启慢查询
33-
slow_query_log = 1
34-
# 开启慢查询时间,此处为3秒,达到此值才记录数据
35-
long_query_time = 3
36-
# 检索行数达到此数值,才记录慢查询日志中
37-
min_examined_row_limit = 10
38-
# 慢查询日志文件地址
39-
slow-query-log-file = /var/log/mysqld-slow.log
40-
# 开启记录没有使用索引查询语句
41-
log_queries_not_using_indexes = 1
42-
# mysql清除过期日志的时间,默认值0,不自动清理,而是使用滚动循环的方式。这里设置为30天
43-
binlog_expire_logs_seconds = 2592000
44-
# 如果二进制日志写入的内容超出给定值,日志就会发生滚动。你不能将该变量设置为大于1GB或小于4096字节。 默认值是1GB。
45-
max_binlog_size = 1000M
41+
tmp_table_size = 32M
42+
max_heap_table_size = 32M
43+
max_connections = 10000
44+
open_files_limit = 65535
45+
46+
[client]
47+
socket = /var/lib/mysql/mysql.sock
48+
port = 3306

codes/linux/soft/mysql-install.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ printf "${CYAN}>>>> replace settings${RESET}\n"
4949
cp /etc/my.cnf /etc/my.cnf.bak
5050
wget -N https://gitee.com/turnon/linux-tutorial/raw/master/codes/linux/soft/config/mysql/my.cnf -O /etc/my.cnf
5151
# 创建空的慢查询日志文件
52-
touch /var/log/mysqld-slow.log
53-
chmod 777 /var/log/mysqld-slow.log
52+
mkdir -p /var/log/mysql
53+
touch /var/log/mysql/mysql-slow.log
54+
chmod 777 /var/log/mysql/mysql-slow.log
55+
chown -R mysql:mysql /var/log/mysql
5456

5557
# 设置开机启动
5658
printf "${CYAN}>>>> start mysqld${RESET}\n"
5759
systemctl enable mysqld
5860
systemctl start mysqld
5961
systemctl daemon-reload
6062

63+
cat >> /etc/security/limits.conf << EOF
64+
mysql soft nofile 65536
65+
mysql hard nofile 65536
66+
EOF
67+
6168
password=$(grep "password" /var/log/mysqld.log | awk '{print $NF}')
6269
printf "临时密码为:${PURPLE}${password}${RESET},请登录 mysql 后重置新密码\n"
6370

0 commit comments

Comments
 (0)