NetworkHow To

ปรับ MariaDB my.cnf สำหรับ RAM 1 GB หรือมากกว่า

มีปัญหามาซักพักกับการที่ MariaDB ดับไปเองบ้าง รีสตาร์ทบ่อยๆ บ้าง ปรับแก้ my.cnf ก็ไม่นิ่งซะทีจนไปเจอ Code แล้วเอามาปรับแก้ max_connections อีกทีจนนิ่งสนิท ตัวนี้จะเป็นตัวสำหรับ RAM 1 GB

วิธีปรับของ Centos

# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
max_connections=100
wait_timeout=30
interactive_timeout=50
long_query_time=5
#log-queries-not-using-indexes
#log-slow-queries=/var/log/mysql/log-slow-queries.log

#innodb_use_native_aio = 0
innodb_file_per_table

[mysqld_safe]

log-error=/var/log/mysqld.log

ใครที่ใช้ VestaCP จะปรับง่ายหน่อยเข้าไปที่ Server > mariadb (database server) > Configure > ADVANCED OPTIONS กรอก Code เข้าไปแล้วทำการรีสตาร์ท

configure

Code ตัวนี้จะเป็น Ram 2 GB ขึ้นไป

[mysqld]
local-infile=0

innodb_buffer_pool_size=128M
innodb_log_buffer_size=2M
innodb_flush_log_at_trx_commit = 1
innodb_thread_concurrency=2
innodb_file_per_table

skip-character-set-client-handshake
skip-name-resolve
max_connections = 200
key_buffer_size = 256M
myisam_sort_buffer_size = 32M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 2M
read_rnd_buffer_size = 1M

table_cache = 1536
thread_concurrency = 2
thread_cache_size = 256
wait_timeout = 3600
connect_timeout = 10
max_tmp_tables = 256
tmp_table_size = 128M
max_allowed_packet = 16M
max_connect_errors = 10
query_cache_limit = 1M
query_cache_size = 32M
query_cache_type = 1
query_prealloc_size = 16384
query_alloc_block_size = 16384
max_heap_table_size = 128M
#tmpdir=/var/mysqltmp

log_warnings=0

[mysqld_safe]

log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid open_files_limit = 16384

Code จากคุณ – icez

Tanjen S.

ศึกษาการทำ Blog มาหลายปีและเริ่มศึกษาเรื่อง SEO มาได้ 10 ปี จนรู้ว่า Google ต้องการอะไร สามารถทำให้หน้าที่เขียนบทความไปสามารถติดหน้าแรกของ Google

Related Articles