Ubuntu中MySQL的参数文件my.cnf示例详析

前言

对于MySQL的理解,我认为很多性能优化工作、主从主主复制都是在调整参数,来适应不同时期不同数量级的数据。

故,理解透彻my.cnf里的参数是永恒的话题;只有理解透彻了参数设置,才能在某些方面对数据库进行调优。

前几天刚接手一个MySQL数据,操作系统为Ubuntu 16.04.5 LTS,  数据库版本为5.7.23-0ubuntu0.16.04.1(APT方式安装的MySQL)。这个操作系统下的MySQL的配置文件my.cnf很多地方都让人有点不适应(跟之前的MySQL环境有些出入,之前都是维护RHEL、CentOS等操作系统环境下的MySQL)。

遂研究总结了一下。具体如下所示:

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 

从上面这些信息判断,MySQL的参数文件为/etc/mysql/my.cnf, 但是其他几个my.cnf又是什么情况呢?

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

从上面信息可以看出,/etc/alternatives/my.cnf 其实是一个软连接,指向参数文件/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

光从上面这些信息,我们还看不出/var/lib/dpkg/alternatives/my.cnf与其它配置文件my.cnf是什么关系。那么我们先来看看参数文件/etc/mysql/my.cnf,从下面信息,可以看出“/etc/mysql/my.cnf”是全局配置,“~/.my.cnf”隐藏文件是个人用户设置.

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/

但是/etc/mysql/my.cnf参数文件下面没有任何参数设置,只看到下面两行设置,表示导入这两个目录里面的配置文件。

!includedir /etc/mysql/conf.d/

#表示包含/etc/mysql/conf.d/这个路径下面的配置文件,前提是必须以为.cnf为后缀

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

#表示包含/etc/mysql/mysql.conf.d/这个路径下面的配置文件,前提是必须以为.cnf为后缀

其实MySQL的相关配置都位于mysqld.cnf(/etc/mysql/mysql.conf.d/mysqld.cnf)下面。使用相关参数测试了一下,确实都能生效。这种设置确实有点让刚接触的人有点不适应。暂时先总结到此!

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 is 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

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对我们的支持。

(0)

相关推荐

  • MariaDB(Mysql分支)my.cnf配置文件中文注释版

    复制代码 代码如下: # /usr/share/mysql/my-huge.cnf # MariaDB 配置文件 示例模板(huge,巨型).## 本文件适用于专用数据库服务器, 内存为 1G-2G# 机器上主要只运行 MariaDB的大型系统 ,## MariaDB 程序会根据运行的操作系统平台查找一系列的配置文件,# 你可以将此模板配置文件拷贝到对应的位置(并重命名),# 要查看有哪些配置文件会被读取到,执行:# 'my_print_defaults --help' 并查看# Default

  • mysql服务性能优化—my.cnf_my.ini配置说明详解(16G内存)

    此配置是老男孩生产线上使用的配置,在培训的时候,他给的,我在这里,对各参数添加了中文说明 这配置已经优化的不错了,如果你的mysql没有什么特殊情况的话,可以直接使用该配置参数 MYSQL服务器my.cnf配置文档详解 硬件:内存16G [client] port = 3306 socket = /data/3306/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3306 socket = /data/3306/my

  • mysql通过my.cnf修改默认字符集为utf-8的方法和注意事项

    选项配置 配置文件路径: /full/path/mysql/bin/my.cnf (默认为/etc/my.cnf ) [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=ut

  • MySQL配置文件my.cnf中文详解附mysql性能优化方法分享

    下面先说我的服务器的硬件以及论坛情况,CPU: 2颗四核Intel Xeon 2.00GHz内存: 4GB DDR硬盘: SCSI 146GB论坛:在线会员 一般在 5000 人左右 – 最高记录是 13264.下面,我们根据以上硬件配置结合一份已经做过一次优化的my.cnf进行分析说明:有些参数可能还得根据论坛的变化情况以及程序员的程序进行再调整.[mysqld]port = 3306serverid = 1socket = /tmp/mysql.sockskip-locking # 避免My

  • mysql 查看当前使用的配置文件my.cnf的方法(推荐)

    my.cnf是mysql启动时加载的配置文件,一般会放在mysql的安装目录中,用户也可以放在其他目录加载. 安装mysql后,系统中会有多个my.cnf文件,有些是用于测试的. 使用locate my.cnf命令可以列出所有的my.cnf文件 命令 locate my.cnf 输出 /usr/local/Cellar/mysql/5.6.24/my.cnf /usr/local/Cellar/mysql/5.6.24/mysql-test/include/default_my.cnf /usr

  • MySQL修改my.cnf配置不生效的解决方法

    本文实例讲述了MySQL修改my.cnf配置不生效的解决方法.分享给大家供大家参考,具体如下: 一.问题: 修改了 my.cnf 配置文件后,却不生效,这是怎么回事? 二.原因: 我们注意到,这里只说了修改 my.cnf,并没有说清楚其绝对路径是哪个文件.也就是说,有可能修改的不是正确路径下的my.cnf文件. 在MySQL中,是允许存在多个 my.cnf 配置文件的,有的能对整个系统环境产生影响,例如:/etc/my.cnf.有的则只能影响个别用户,例如:~/.my.cnf. MySQL读取各

  • MySQL配置文件my.cnf优化详解(mysql5.5)

    MySQL 5.5.13 参数说明: [client] character-set-server = utf8 port = 3306 socket = /data/mysql/3306/mysql.sock [mysqld] character-set-server = utf8 user = mysql port = 3306 socket = /data/mysql/3306/mysql.sock basedir = /usr/local/webserver/mysql datadir =

  • MySQL性能优化之路---修改配置文件my.cnf

    在Apache, PHP, MySQL的体系架构中,MySQL对于性能的影响最大,也是关键的核心部分.对于Discuz!论坛程序也是如此,MySQL的设置是否合理优化,直接影响到论坛的速度和承载量!同时,MySQL也是优化难度最大的一个部分,不但需要理解一些MySQL专业知识,同时还需要长时间的观察统计并且根据经验进行判断,然后设置合理的参数. 下面我们了解一下MySQL优化的一些基础,MySQL的优化我分为两个部分,一是服务器物理硬件的优化,二是MySQL自身(my.cnf)的优化. 一.服务

  • 对MySQL配置参数 my.ini/my.cnf的详细解析

    以下的文章主要描述的是对MySQL配置参数 my.ini/my.cnf的详细解析,我们主要是以实例演示的方式来对MySQL配置参数 my.ini/my.cnf的实际操作步骤进行说明,以下就是相关内容的具体描述. 1.获取当前配置参数 要优化MySQL配置参数,首先要了解当前的配置参数以及运行情况.使用下列命令可以获得目前服务器使用的配置参数: 复制代码 代码如下: mysqld –verbose –help mysqladmin variables extended-status –u root

  • MySQL配置文件my.cnf参数优化和中文详解

    Mysql参数优化对于新手来讲,是比较难懂的东西,其实这个参数优化,是个很复杂的东西,对于不同的网站,及其在线量,访问量,帖子数量,网络情况,以及机器硬件配置都有关系,优化不可能一次性完成,需要不断的观察以及调试,才有可能得到最佳效果. 复制代码 代码如下: [client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedir = /usr/local/mysqldatadi

随机推荐