Mysql

安裝成功後配置 MariaDB 的下一步

  • March 3, 2018

除了正式的文件(即https://mariadb.com/resources/blog/installing-mariadb-10-centos-7-rhel-7等),還有無數關於安裝 MariaDB 的教程,然而,沒有之一他們接著說,可能需要額外的步驟來滿足特定的安裝要求。下一個不成文和假定的步驟是否/etc/my.cnf需要根據需要進行修改?當我開始這樣做時,我驚訝地發現我的幾乎是空的,不像典型的冗長配置文件,其中各種配置設置被註釋掉了。這個/etc/my.cnf文件是我應該編輯的文件,還是一些常見的 MySQL/MariaDB 文件,而其他地方還有一些其他 MariaDB 特定文件?或者是否可能沒有配置文件https://mariadb.com/kb/en/library/configuring-mariadb-with-mycnf/提示?如果我想進行各種更改,例如時區等,下一步是什麼?

cat /etc/os-release:

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

PHP version: 7.1.14
cat /etc/yum.repos.d/MariaDB.repo (Gives information on how package was installed.):

# MariaDB 10.2 CentOS repository list - created 2017-07-17 12:45 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
ls -l /etc | grep sql (Nothing):

ls -l /etc | grep maria (Nothing):

ls -l /etc | grep my:

-rw-r--r--   1 root root      202 Feb 12 15:01 my.cnf
drwxr-xr-x   2 root root       78 Feb 19 12:05 my.cnf.d
cat /etc/my.cnf:

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

ls -l /etc/my.cnf.d:

total 12
-rw-r--r-- 1 root root  763 Feb 12 15:01 enable_encryption.preset
-rw-r--r-- 1 root root  232 Feb 12 15:01 mysql-clients.cnf
-rw-r--r-- 1 root root 1080 Feb 12 15:01 server.cnf
tail -n +1 -- /etc/my.cnf.d/*:

==> /etc/my.cnf.d/enable_encryption.preset <==
#
# !include this file into your my.cnf (or any of *.cnf files in /etc/my.cnf.d)
# and it will enable data at rest encryption. This is a simple way to
# ensure that everything that can be encrypted will be and your
# data will not leak unencrypted.
#
# DO NOT EDIT THIS FILE! On MariaDB upgrades it might be replaced with a
# newer version and your edits will be lost. Instead, add your edits
# to the .cnf file after the !include directive.
#
# NOTE that you also need to install an encryption plugin for the encryption
# to work. See https://mariadb.com/kb/en/mariadb/data-at-rest-encryption/#encryption-key-management
#
[mariadb]
aria-encrypt-tables
encrypt-binlog
encrypt-tmp-disk-tables
encrypt-tmp-files
loose-innodb-encrypt-log
loose-innodb-encrypt-tables

==> /etc/my.cnf.d/mysql-clients.cnf <==
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#

[mysql]

[mysql_upgrade]

[mysqladmin]

[mysqlbinlog]

[mysqlcheck]

[mysqldump]

[mysqlimport]

[mysqlshow]

[mysqlslap]


==> /etc/my.cnf.d/server.cnf <==
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]

#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.1 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.1]

ls -l /usr/share/mysql | grep cnf (Should I be swapping out /etc/my.cnf with one of these?):

-rw-r--r-- 1 root root   4920 Feb 12 16:58 my-huge.cnf
-rw-r--r-- 1 root root  20441 Feb 12 16:58 my-innodb-heavy-4G.cnf
-rw-r--r-- 1 root root   4907 Feb 12 16:58 my-large.cnf
-rw-r--r-- 1 root root   4920 Feb 12 16:58 my-medium.cnf
-rw-r--r-- 1 root root   2846 Feb 12 16:58 my-small.cnf
-rw-r--r-- 1 root root   3452 Feb 12 16:58 wsrep.cnf

編輯。啊,mysqld --help --verbosemysqladmin variables部分是我想要的。但問題仍然存在。這些預設設置在哪裡定義,為什麼我找不到任何建議修改它們的文件/教程/部落格?

mysqld  Ver 10.2.13-MariaDB for Linux on x86_64 (MariaDB Server)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-10.2 mariadb mariadb-10.2 client-server galera
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit.
--no-defaults           Don't read default options from any option file.

....

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}                           Value (after reading options)
---------------------------------------------------------- ---------------
allow-suspicious-udfs                                      FALSE
aria                                                       ON
aria-block-size                                            8192
aria-checkpoint-interval                           

PS。以下內容用於生成以上內容,僅供參考。

<?php
function execute($cmd, $extra=null) {
   echo '<p>'.$cmd.($extra?'   ('.$extra.')':'').':</p><pre>'.shell_exec($cmd).'</pre>';
}

echo execute('cat /etc/os-release');
echo 'PHP version: ' . phpversion().'<br>';
echo execute('cat /etc/yum.repos.d/MariaDB.repo','Gives information on how package was installed.');
echo execute('ls -l /etc | grep sql','Nothing');
echo execute('ls -l /etc | grep maria','Nothing');
echo execute('ls -l /etc | grep my');
echo execute('cat /etc/my.cnf');
echo execute('ls -l /etc/my.cnf.d');
echo execute('tail -n +1 -- /etc/my.cnf.d/*');
echo execute('ls -l /usr/share/mysql | grep cnf','Should I be swapping out /etc/my.cnf with one of these?');

my.cnf設置(包括)(如果有)位於my.cnf.d/*內置預設值之前。對於通用安裝,所有這些都是“合理的”。

只有在您發現您的應用程序不是“平均”之後,添加(或更改它們)才是重要的。

最重要的設置(對於性能)是innodb_buffer_pool_size; 它應該設置為可用記憶體的 70% 左右。幾乎所有其他東西(有數百個“變數”)都不需要在沒有充分理由的情況下進行更改。

誠然,這個論壇充滿了與my.cnf. 我發現它們分為以下幾類:

  • “越大越好”——使用者在不了解負面影響(例如記憶體不足)的情況下通過增加各種設置而陷入困境。
  • “我的網站很慢;幫我調整”——答案幾乎總是涉及INDEXes和/或查詢公式,而不是調整。
  • “我認為…”——許多可調參數是微妙的、模棱兩可的、難以理解的等。而且這個可調參數與該問題的關係很少很明顯。

要獲取完整列表(例如,來自命令行工具“mysql”):

SHOW VARIABLES;

我給了你一件事來改變;在您得到具體建議之前,不要擔心改變任何其他人。

引用自:https://dba.stackexchange.com/questions/198737