mariadb配置文件优化参数

本文提供了针对128G内存32线程及256G内存64线程处理器的MariaDB数据库优化配置参数。涉及连接数、缓存大小、日志记录等多个方面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mariadb数据库优化需要根据自己业务需求以及根据硬件配置来进行参数优化,下面是一些关于mariadb数据库参数优化的配置文件。

如下为128G内存32线程处理器的mariadb配置参数优化:

[client]

#password= your_password

port= 3306         

socket= /tmp/mysql.sock

!includedir /opt/local/mysql/wsrep

# The MySQL server

[mysqld]

port= 3306

socket= /tmp/mysql.sock

basedir = /opt/local/mysql

datadir=/opt/local/mysql/data                   #数据库存放目录

relay-log=/opt/local/mysql/relaylog/s74-relay-bin                         

pid-file = /opt/local/mysql/mysql.pid

log-error = /opt/local/mysql/logs/mysqld.log

open_files_limit = 65535                        #

#skip-locking

skip-external-locking                           #跳过外部锁定

back_log=3000                                   #暂存的连接数量  

skip-name-resolve                               #关闭mysql的dns反查功能

memlock                                         #将mysqld 进程锁定在内存中

lower_case_table_names = 1

#query_response_time_stats=1

#core-file

#core-file-size = unlimited

query_cache_type=1                              #查询缓存  (0 = off、1 = on、2 = demand)

performance_schema=0                            #收集数据库服务器性能参数

net_read_timeout=3600                           #连接繁忙阶段(query)起作用

net_write_timeout=3600                          #连接繁忙阶段(query)起作用

key_buffer_size = 32M                           #设置索引块缓存大小

max_allowed_packet = 128M                       #通信缓冲大小

table_open_cache = 1024                         #table高速缓存的数量

sort_buffer_size = 12M                          #每个connection(session)第一次需要使用这个buffer的时候,一次性分配设置的内存

read_buffer_size = 8M                           #顺序读取数据缓冲区使用内存

#sort_buffer_size = 32M

#read_buffer_size = 32M

read_rnd_buffer_size = 32M                      #随机读取数据缓冲区使用内存

myisam_sort_buffer_size = 32M                   #MyISAM表发生变化时重新排序所需的缓冲

thread_cache_size = 120                         #重新利用保存在缓存中线程的数量

query_cache_size = 64M

join_buffer_size = 8M                           #Join操作使用内存

bulk_insert_buffer_size = 32M                   #批量插入数据缓存大小

delay_key_write=ON                              #在表关闭之前,将对表的update操作指跟新数据到磁盘,而不更新索引到磁盘,把对索引的更改记录在内存。这样MyISAM表可以使索引更新更快。在关闭表的时候一起更新索引到磁盘

delayed_insert_limit=4000

delayed_insert_timeout=600

delayed_queue_size=4000

# Try number of CPU's*2 for thread_concurrency

# The variable only affects Solaris!

thread_concurrency = 64                         #CPU核数 * 2

max_connections=1500                            #最大连接(用户)数。每个连接MySQL的用户均算作一个连接

max_connect_errors=30                           #最大失败连接限制

interactive_timeout=600                         #服务器关闭交互式连接前等待活动的秒数

wait_timeout=3600                               #服务器关闭非交互连接之前等待活动的秒数

slow_query_log                                  #慢查询记录日志

long_query_time = 0.1                           #慢查询记录时间  0.1秒

slow_query_log_file=/opt/local/mysql/logs/slow_query.log            #慢查询日志路径

#log_slow_verbosity=full

log_slow_verbosity=query_plan                   #

# Replication Master Server (default)

# binary logging is required for replication

log-bin=/opt/local/mysql/binlog/mysql-bin                               #binlog 名称

log-slave-updates                               #从master取得并执行的二进制日志写入自己的二进制日志文件中

replicate-ignore-db=mysql                       #不同步的表

# binary logging format - mixed recommended

binlog_format=row                               #binlog 格式 分别为 row=行格式 丶 mixed=混合格式 丶 STATEMENT=SQL语句复制模式

event_scheduler=1                               #计划任务 事件调度器

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master if omitted

server-id= 1                                 #

# Point the following paths to different dedicated disks

#tmpdir= /tmp/

#log-update = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using InnoDB tables

#innodb_data_home_dir = /data/mysql-5.1.48/mysql-data/

#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend

#innodb_log_group_home_dir = /data/mysql-5.1.48/mysql-data/

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

innodb_file_format=barracuda

innodb_file_format_max=barracuda

innodb_file_per_table=1

innodb_fast_shutdown=0

innodb_buffer_pool_size = 90000M

innodb_buffer_pool_instances = 4

#innodb_additional_mem_pool_size = 20M

#innodb_use_sys_malloc = 20M

# Set .._log_file_size to 25 % of buffer pool size

innodb_log_file_size = 512M

#innodb_log_buffer_size = 8M

innodb_log_files_in_group = 3

innodb_flush_log_at_trx_commit = 2

innodb_lock_wait_timeout = 3 

innodb_rollback_on_timeout = on

innodb_flush_method=O_DIRECT

transaction-isolation=READ-COMMITTED

innodb_thread_concurrency=0

innodb_io_capacity=800

innodb_purge_threads=1

innodb_open_files=65535

#innodb_stats_update_need_lock=0

#innodb_flush_neighbor_pages=0 

#innodb_aio_pending_ios_per_thread=256

#for binlog_format=row

innodb_autoinc_lock_mode=2

#innodb_fast_checksum = 1

innodb_read_io_threads = 8

innodb_write_io_threads = 12

innodb_stats_on_metadata = 0

#使用线程池处理连接

thread_handling=pool-of-threads

thread_pool_oversubscribe=30

thread_pool_size=64

thread_pool_idle_timeout=7200

thread_pool_max_threads=2000

#查询优化器开关

#optimizer_switch='index_condition_pushdown=on'

#optimizer_switch='mrr=on'

#optimizer_switch='mrr_sort_keys=on'

#optimizer_switch='mrr_cost_based=off'

#mrr_buffer_size=32M

#optimizer_switch='join_cache_incremental=on'

#optimizer_switch='join_cache_hashed=on'

#optimizer_switch='join_cache_bka=on'

#join_cache_level=4

#join_buffer_size=32M

#join_buffer_space_limit=32M

[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 = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[isamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

 

如下为256G内存64线程处理器的mariadb配置参数优化:

[client]

#password= your_password

port= 3306         

socket= /tmp/mysql.sock

!includedir /opt/local/mysql/wsrep

# The MySQL server

[mysqld]

port= 3306

socket= /tmp/mysql.sock

basedir = /opt/local/mysql

datadir=/opt/local/mysql/data                   #数据库存放目录

relay-log=/opt/local/mysql/relaylog/s74-relay-bin                         

pid-file = /opt/local/mysql/mysql.pid

log-error = /opt/local/mysql/logs/mysqld.log

open_files_limit = 65535                        #

#skip-locking

skip-external-locking                           #跳过外部锁定

back_log=3000                                   #暂存的连接数量  

skip-name-resolve                               #关闭mysql的dns反查功能

memlock                                         #将mysqld 进程锁定在内存中

lower_case_table_names = 1

#query_response_time_stats=1

#core-file

#core-file-size = unlimited

query_cache_type=1                              #查询缓存  (0 = off、1 = on、2 = demand)

performance_schema=0                            #收集数据库服务器性能参数

net_read_timeout=3600                           #连接繁忙阶段(query)起作用

net_write_timeout=3600                          #连接繁忙阶段(query)起作用

key_buffer_size = 32M                           #设置索引块缓存大小

max_allowed_packet = 128M                       #通信缓冲大小

table_open_cache = 1024                         #table高速缓存的数量

sort_buffer_size = 12M                          #每个connection(session)第一次需要使用这个buffer的时候,一次性分配设置的内存

read_buffer_size = 8M                           #顺序读取数据缓冲区使用内存

#sort_buffer_size = 32M

#read_buffer_size = 32M

read_rnd_buffer_size = 32M                      #随机读取数据缓冲区使用内存

myisam_sort_buffer_size = 32M                   #MyISAM表发生变化时重新排序所需的缓冲

thread_cache_size = 120                         #重新利用保存在缓存中线程的数量

query_cache_size = 64M

join_buffer_size = 8M                           #Join操作使用内存

bulk_insert_buffer_size = 32M                   #批量插入数据缓存大小

delay_key_write=ON                              #在表关闭之前,将对表的update操作指跟新数据到磁盘,而不更新索引到磁盘,把对索引的更改记录在内存。这样MyISAM表可以使索引更新更快。在关闭表的时候一起更新索引到磁盘

delayed_insert_limit=4000

delayed_insert_timeout=600

delayed_queue_size=4000

# Try number of CPU's*2 for thread_concurrency

# The variable only affects Solaris!

thread_concurrency = 96                          #CPU核数 * 2

max_connections=1500                            #最大连接(用户)数。每个连接MySQL的用户均算作一个连接

max_connect_errors=30                           #最大失败连接限制

interactive_timeout=600                         #服务器关闭交互式连接前等待活动的秒数

wait_timeout=3600                               #服务器关闭非交互连接之前等待活动的秒数

slow_query_log                                  #慢查询记录日志

long_query_time = 0.1                           #慢查询记录时间  0.1秒

slow_query_log_file=/opt/local/mysql/logs/slow_query.log            #慢查询日志路径

#log_slow_verbosity=full

log_slow_verbosity=query_plan                   #

# Replication Master Server (default)

# binary logging is required for replication

log-bin=/opt/local/mysql/binlog/mysql-bin                               #binlog 名称

log-slave-updates                               #从master取得并执行的二进制日志写入自己的二进制日志文件中

replicate-ignore-db=mysql                       #不同步的表

# binary logging format - mixed recommended

binlog_format=row                               #binlog 格式 分别为 row=行格式 丶 mixed=混合格式 丶 STATEMENT=SQL语句复制模式

event_scheduler=1                               #计划任务 事件调度器

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master if omitted

server-id= 1                                 #

# Point the following paths to different dedicated disks

#tmpdir= /tmp/

#log-update = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using InnoDB tables

#innodb_data_home_dir = /data/mysql-5.1.48/mysql-data/

#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend

#innodb_log_group_home_dir = /data/mysql-5.1.48/mysql-data/

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

innodb_file_format=barracuda

innodb_file_format_max=barracuda

innodb_file_per_table=1

innodb_fast_shutdown=0

innodb_buffer_pool_size = 180000M

innodb_buffer_pool_instances = 4

#innodb_additional_mem_pool_size = 20M

#innodb_use_sys_malloc = 20M

# Set .._log_file_size to 25 % of buffer pool size

innodb_log_file_size = 512M

#innodb_log_buffer_size = 8M

innodb_log_files_in_group = 3

innodb_flush_log_at_trx_commit = 2

innodb_lock_wait_timeout = 3 

innodb_rollback_on_timeout = on

innodb_flush_method=O_DIRECT

transaction-isolation=READ-COMMITTED

innodb_thread_concurrency=0

innodb_io_capacity=800

innodb_purge_threads=1

innodb_open_files=65535

#innodb_stats_update_need_lock=0

#innodb_flush_neighbor_pages=0 

#innodb_aio_pending_ios_per_thread=256

#for binlog_format=row

innodb_autoinc_lock_mode=2

#innodb_fast_checksum = 1

innodb_read_io_threads = 8

innodb_write_io_threads = 12

innodb_stats_on_metadata = 0

#使用线程池处理连接

thread_handling=pool-of-threads

thread_pool_oversubscribe=30

thread_pool_size=64

thread_pool_idle_timeout=7200

thread_pool_max_threads=2000

#查询优化器开关

#optimizer_switch='index_condition_pushdown=on'

#optimizer_switch='mrr=on'

#optimizer_switch='mrr_sort_keys=on'

#optimizer_switch='mrr_cost_based=off'

#mrr_buffer_size=32M

#optimizer_switch='join_cache_incremental=on'

#optimizer_switch='join_cache_hashed=on'

#optimizer_switch='join_cache_bka=on'

#join_cache_level=4

#join_buffer_size=32M

#join_buffer_space_limit=32M

[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 = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[isamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

 

转载于:https://my.oschina.net/mickelfeng/blog/904519

<think>我们正在讨论MariaDB配置文件位置。根据Linux系统和安装方式的不同,配置文件路径可能有所变化。对于使用yum安装的MariaDB,通常配置文件位于/etc/my.cnf或/etc/my.cnf.d/目录下。此外,MariaDB也可能读取其他位置的配置文件,但标准位置是/etc/my.cnf。根据常见的Linux发行版(如CentOS、RHEL)的惯例,yum安装的MariaDB配置文件通常位于:1.主配置文件:/etc/my.cnf2.额外的配置文件目录:/etc/my.cnf.d/(在这个目录中,配置文件通常以.cnf结尾)此外,MariaDB服务启动时可能会读取其他位置的配置文件,但上述位置是最常见的。为了确保准确,我们可以通过以下方法查找:1.使用mysqld命令查看:运行`mysqld--help--verbose|grep-A1"Defaultoptions"`,这将显示MariaDB服务器在启动时读取的默认选项文件。2.查看MariaDB服务启动脚本,但通常我们不需要这么复杂。然而,用户是通过yum安装的,所以我们可以直接检查上述标准路径。另外,根据引用[1]和引用[2]的内容,它们提到的是安装MariaDB的过程,并没有直接提及配置文件路径。但根据常规知识,我们可以确定上述路径。因此,我们可以这样回答用户:使用yum安装MariaDB后,配置文件通常位于:-主配置文件:/etc/my.cnf-额外的配置文件目录:/etc/my.cnf.d/(该目录下的.cnf文件也会被读取)同时,为了确保用户能够找到,建议用户使用以下命令查看MariaDB当前加载的配置文件:```bashmysql--help|grep"Defaultoptions"-A1```或者```bashmysqld--help--verbose|grep"Defaultoptions"-A1```这个命令将显示MariaDB启动时读取配置文件的顺序,它会按照列出的顺序读取多个配置文件(如果有的话)。注意:由于用户可能使用的是不同的版本或系统,但通常路径是一致的。相关问题:1.如何修改MariaDB配置文件?2.MariaDB配置文件有哪些常用配置项?3.如何让MariaDB重新加载配置文件而不重启服务?</think>### MariaDB 配置文件路径 使用 `yum` 安装 MariaDB 后,配置文件的标准路径如下: 1. **主配置文件** `/etc/my.cnf` 这是 MariaDB 服务启动时加载的核心配置文件。 2. **附加配置目录** `/etc/my.cnf.d/` 该目录包含额外的配置文件(扩展名为 `.cnf`),MariaDB 会自动加载其中的文件,例如: - `server.cnf`:服务器配置 - `client.cnf`:客户端连接配置 - `mariadb-server.cnf`:服务端优化参数 --- ### 验证配置文件路径的方法 1. **通过 MySQL 命令查询** 执行以下命令查看配置加载顺序: ```bash mysql --help | grep "Default options" -A 1 ``` 输出示例: ``` Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf ``` 2. **检查服务启动配置** 查看 systemd 服务文件: ```bash systemctl cat mariadb ``` 在 `[Service]` 部分查找 `--defaults-file` 参数,明确指定配置文件路径(若有)。 --- ### 配置文件示例结构 典型的 `/etc/my.cnf` 内容: ```ini [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d # 加载附加配置 ``` --- ### 关键说明 - MariaDB 兼容 MySQL 配置路径,因此使用 MySQL 的相同路径规范[^1]。 - 修改配置后需重启服务生效: ```bash sudo systemctl restart mariadb ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值