Detailed analysis of the parameter file my.cnf of MySQL in Ubuntu

Detailed analysis of the parameter file my.cnf of MySQL in Ubuntu

Preface

Based on my understanding of MySQL, I think a lot of performance optimization work and master-slave replication are about adjusting parameters to adapt to data of different orders of magnitude in different periods.

Therefore, a thorough understanding of the parameters in my.cnf is an eternal topic; only by thoroughly understanding the parameter settings can we tune the database in certain aspects.

I just took over a MySQL database a few days ago. The operating system is Ubuntu 16.04.5 LTS and the database version is 5.7.23-0ubuntu0.16.04.1 (MySQL installed by APT). There are many things about the MySQL configuration file my.cnf under this operating system that make people feel a little uncomfortable (it is somewhat different from the previous MySQL environment, where I previously maintained MySQL under operating system environments such as RHEL and CentOS).

So I did some research and summarized it. The details are as follows:

root@mylnx12:~# find / -name "my.cnf"
/etc/alternatives/my.cnf
/etc/mysql/my.cnf
/var/lib/dpkg/alternatives/my.cnf
root@mylnx12:~# locate my.cnf
/etc/alternatives/my.cnf
/etc/mysql/my.cnf
/etc/mysql/my.cnf.fallback
/var/lib/dpkg/alternatives/my.cnf
root@mylnx12:~# mysql --help | grep my.cnf
      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 
root@mylnx12:~# mysqld --verbose --help | grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

Judging from the above information, the MySQL parameter file is /etc/mysql/my.cnf, but what about the other my.cnf files?

root@mylnx12:~# ls -lrt /etc/alternatives/my.cnf
lrwxrwxrwx 1 root root 20 Sep 28 16:28 /etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf

From the above information, we can see that /etc/alternatives/my.cnf is actually a soft link pointing to the parameter file /etc/mysql/mysql.cnf

root@mylnx12:~# cat /var/lib/dpkg/alternatives/my.cnf
auto
/etc/mysql/my.cnf
 
/etc/mysql/my.cnf.fallback
100
/etc/mysql/mysql.cnf
200

From the above information alone, we still cannot see the relationship between /var/lib/dpkg/alternatives/my.cnf and other configuration files my.cnf. Then let's take a look at the parameter file /etc/mysql/my.cnf. From the following information, we can see that "/etc/mysql/my.cnf" is a global configuration, and the "~/.my.cnf" hidden file is a personal user setting.

root@mylnx12:~# cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
 
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

However, there are no parameter settings under the /etc/mysql/my.cnf parameter file. Only the following two lines of settings are seen, indicating that the configuration files in these two directories are imported.

!includedir /etc/mysql/conf.d/

# indicates that the configuration files under the path /etc/mysql/conf.d/ are included, provided that the suffix is ​​.cnf

!includedir /etc/mysql/mysql.conf.d/

# indicates that the configuration files under the path /etc/mysql/mysql.conf.d/ are included, provided that the suffix is ​​.cnf

In fact, all MySQL related configurations are located under mysqld.cnf (/etc/mysql/mysql.conf.d/mysqld.cnf). I tested it with the relevant parameters and it worked. This kind of setting is indeed a bit uncomfortable for those who are new to it. That’s the summary for now!

root@mylnx12:~# cd /etc/mysql/mysql.conf.d/
root@mylnx12:/etc/mysql/mysql.conf.d# ls -lrt
total 8
-rw-r--r-- 1 root root 21 Feb 4 2017 mysqld_safe_syslog.cnf
-rw-r--r-- 1 root root 3148 Oct 6 23:34 mysqld.cnf
root@mylnx12:/etc/mysql/mysql.conf.d# cat mysqld.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
 
# Here are entries for some specific programs
# The following values ​​assume you have at least 32M ram
 
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
 
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
log_bin = mylnx12_bin
server_id = 0
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
 
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 10.21.6.7
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 100M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
#: ssl-key=/etc/mysql/server-key.pem

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the problem that the configuration file my.cnf in MySQL cannot be started due to permission issues
  • mysql method to view the currently used configuration file my.cnf (recommended)
  • How to modify the default character set of MySQL to utf-8 through my.cnf and precautions
  • MySQL service performance optimization—my.cnf_my.ini configuration instructions (16G memory)
  • Introduction to /etc/my.cnf parameters in MySQL 5.7

<<:  Complete Tutorial on Deploying Java Web Project on Linux Server

>>:  Detailed explanation of the middleman mode of Angular components

Recommend

Teach you to implement a simple promise step by step

Table of contents Step 1: Build the framework Ste...

Understand the principle of page replacement algorithm through code examples

Page replacement algorithm: The essence is to mak...

An article to solve the echarts map carousel highlight

Table of contents Preface toDoList just do it Pre...

MySQL series tutorials for beginners

Table of contents 1. Basic concepts and basic com...

Detailed explanation of MySQL monitoring tool mysql-monitor

1. Overview mysql-monitor MYSQL monitoring tool, ...

Blog Design Web Design Debut

The first web page I designed is as follows: I ha...

JavaScript BOM Explained

Table of contents 1. BOM Introduction 1. JavaScri...

Solve the problem of PhPStudy MySQL startup failure under Windows system

Report an error The Apache\Nginx service started ...

Use JS to zoom in and out when you put the mouse on the image

Use JS to zoom in and out when the mouse is on th...

Detailed explanation of Linux rpm and yum commands and usage

RPM package management A packaging and installati...

Vue-cli creates a project and analyzes the project structure

Table of contents 1. Enter a directory and create...

Detailed tutorial on deploying SpringBoot + Vue project to Linux server

Preface Let me share with you how I deployed a Sp...

jQuery implements the function of adding and deleting employee information

This article shares the specific code of jQuery t...