Configuratiebestanden (MySQL): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
(28 tussenliggende versies door dezelfde gebruiker niet weergegeven)
Regel 1: Regel 1:
Altijd verwarrend waar je systeeminstellingen van MySQL aanpast. Daarnaast is MySQL nogal kritisch als het om wijzigingen gaat. Er zijn twee soorten bestanden: Systeem-wijde instellingen in ''/etc'' en gebruiker-specifieke instellingen in ''~/''. Dit artikel gaat vooral over deze eerste.
+
In MySQL kun je instellingen configureren per gebruiker, of per systeem. Beiden worden in dit artikel behandeld.  
  
== Spoorzoeken ==
+
Let op: MySQL is nogal kritisch als het om wijzigingen gaat. Daarom maak ik soms een backup voor ik iets om zeep help. Als het om MySQL-configuratiebestanden gaat, voeg ik een extensie aan het eind toe. Bv. <code>my.cnf.bk01</code>.
 
 
Er is een verwarrend woud aan placeholder-configuratiebestanden, die ook nog 's allemaal naar elkaar lijken te verwijzen:
 
 
 
=== System-wide ===
 
 
 
<pre>
 
* /etc/mysql/
 
 
 
  * debian.cnf
 
  * debian-start
 
  * my.cnf → /etc/alternatives/my.cnf → /etc/mysql/mysql.cnf (echt waar!)
 
  * my.cnf.fallback
 
  * mysql.cnf
 
 
 
  * mysql.conf.d/
 
    * mysqld.cnf
 
    * mysqld_safe_syslog.cnf
 
</pre>
 
 
 
Maar daar houdt het niet op, want dit is de inhoud van de 'placeholder' files hierboven:
 
 
 
<pre>
 
!includedir /etc/mysql/conf.d/
 
!includedir /etc/mysql/mysql.conf.d/
 
</pre>
 
 
 
=== User-specific ===
 
 
 
In je home dit heb je een bestand <code>.my.cnf</code>.
 
 
 
== Niet meer spoorzoeken ==
 
 
 
Voor systeem-brede aanpassingen:
 
 
 
<pre>
 
cd /etc/mysql
 
sudo mv my.cnf my.cnf.oud
 
sudo cp mysql.cnf my.cnf
 
</pre>
 
 
 
Gebruik nu bestand <code>my.cnf</code> voor eigen instellingen.
 
 
 
* Bron: Uitleg in bestand mysql.cnf
 
* Verder vind je default-instellingen in <code>/etc/mysql/mysql.conf.d/mysql.cnf</code> - Handig om dingen af te kijken.
 
  
 
== .my.cnf ==
 
== .my.cnf ==
  
In je home dir staat doorgaans een bestand <code>.my.cnf</code>. Mijn versie (licht bijgewerkt, april 2020):
+
<code>.my.cnf</code> is het configuratiebestand met gebruiker-specifieke instellingen. Dit bestand staat doorgaans direct in je ''home dir''. Mijn versie (licht bijgewerkt, april 2020):
  
 
<pre>
 
<pre>
################################################################################################
+
###########################################################################
# [Client]
+
[Client]
################################################################################################
+
###########################################################################
#
 
[client]
 
host  = localhost
 
socket = /var/run/mysqld/mysqld.sock
 
 
 
 
 
# Specifying user & password to avoid authentication
 
####################################################
 
 
#
 
#
 +
host    = localhost
 +
socket  = /var/run/mysqld/mysqld.sock
 
user    = supervrouw
 
user    = supervrouw
 
password = mijnwachtwoord
 
password = mijnwachtwoord
  
  
# Include comments when importing sql-files
+
# Include comments when inserting sql-dumps
####################################################
+
##############################################
 
#
 
#
 
comments = true
 
comments = true
  
  
################################################################################################
+
# local_infile - Added Aug. 17, 2020
# [mysqldump]
+
##########################################
################################################################################################
 
 
#
 
#
[mysqldump]
+
local_infile=ON
  
  
 +
###########################################################################
 +
[mysqldump]
 +
###########################################################################
 +
#
 
# Include sprocs & functions when making dumps
 
# Include sprocs & functions when making dumps
 
##############################################
 
##############################################
Regel 87: Regel 40:
  
  
# Continue with dump despite errors in views
+
# Continue with dump despite errors
 
##############################################
 
##############################################
 
#
 
#
Regel 93: Regel 46:
 
</pre>
 
</pre>
  
== Backups van configuratiebestanden ==
+
Maak dit bestand enkel leesbaar voor de eigenaar:
  
Configuratiebestanden moeten welliswaar de extensie <code>.cnf</code> hebben, maar niet alle bestanden met de extensie <code>.cnf</code> worden automatisch uitgevoerd. Je kunt dus backups maken met namen zoals <code>my.cnf.bk01</code>.
+
<code>
 +
chmod 0600 ~/.my.cnf
 +
</code>
  
== Voorbeeld: Aanpassen secure_file_priv ==
+
== Instellingen op serverniveau ==
  
Vantevoren:
+
Het kan verwarrend zijn waar je systeembrede instellingen moet toepassen, maar ingewikkelder dan dit hoeft 't niet te zijn:
<pre>
 
mysql> show variables like "secure_file_priv";
 
+------------------+----------------------------+
 
| Variable_name    | Value                      |
 
+------------------+----------------------------+
 
| secure_file_priv | /var/lib/mysql-files/      |
 
+------------------+----------------------------+
 
1 row in set (0,00 sec)
 
</pre>
 
 
 
Ik heb bestand <code>/etc/mysql/my.cnf</code> aangepast. Dit is nu het hele bestand:
 
  
 
<pre>
 
<pre>
!includedir /etc/mysql/conf.d/
+
cd /etc/mysql
!includedir /etc/mysql/mysql.conf.d/
+
sudo mv my.cnf my.cnf.bk-org
 
+
sudo vim my.cnf
##################################################
 
# HERE IS MY OWN STUFF - STROMPF
 
##################################################
 
#
 
[mysqld]
 
secure-file-priv = ""
 
 
</pre>
 
</pre>
  
En het werkt:
+
* Gebruik bestand <code>my.cnf</code> voor eigen instellingen
 
+
* Default-instellingen vind je in <code>/etc/mysql/mysql.conf.d/mysql.cnf</code> - Handig om dingen af te kijken
<pre>
+
* Na aanpassingen moet je de server herstarten, bv. met <code>sudo service mysql restart</code> (niet <code>mysqld</code>)
mysql> show variables like "secure_file_priv";
+
* Tot nov. 2020, kopiëerde ik een bestand eerst naar my.cnf, en voegde m'n eigen dingen toe. Dat bleek een foutmelding te geven!
+------------------+-------+
 
| Variable_name    | Value |
 
+------------------+-------+
 
| secure_file_priv |      |
 
+------------------+-------+
 
1 row in set (0,00 sec)
 
</pre>
 
  
== Mijn /etc/mysql/my.cnf (zomer 2020) ==
+
Mijn /etc/mysql/my.cnf (zomer-herfst 2020)
  
 
[[file:20200529-1434.png|thumb|De configuratie op m'n laptop. <code>my.cnf.fallback</code> is een werkende backup. <code>my.cnf</code> is het actuele bestand, en dat vind je hiernaast in detail]]
 
[[file:20200529-1434.png|thumb|De configuratie op m'n laptop. <code>my.cnf.fallback</code> is een werkende backup. <code>my.cnf</code> is het actuele bestand, en dat vind je hiernaast in detail]]
Regel 143: Regel 74:
  
 
<pre>
 
<pre>
 +
 +
#  MySQL system-wide configuration file
 +
###########################################################################
 
#
 
#
###########################################################################
+
# * This file contains *only* custom settings
# Defaults
+
# * Jeroen Strompf - Nov. 2020
###########################################################################
+
# * See http://wiki.devliegendebrigade.nl/Configuratiebestanden_(MySQL)
 +
#   for details
 
#
 
#
# This line is optional: Server will still start without this line
 
 
#
 
#
!includedir /etc/mysql/conf.d/
 
 
 
 
###########################################################################
 
###########################################################################
# Strompf - [mysqld]
+
# [mysqld]
 
###########################################################################
 
###########################################################################
 
#
 
#
Regel 182: Regel 113:
 
#
 
#
 
max_allowed_packet=536870912
 
max_allowed_packet=536870912
 +
 +
 +
# log_bin_trust_function_creators
 +
###################################
 +
#
 +
# * http://wiki.devliegendebrigade.nl/Unsafe_function_declaration_(MySQL)
 +
# * Dit lijkt echter niet te werken (nov. 2020): Zie de URL hierboven
 +
#
 +
log_bin_trust_function_creators = 1;
 +
 +
 +
# local_infile - Allow LOAD DATA - 17 Aug. 2020
 +
###############################################
 +
#
 +
local_infile=ON
  
  
 
###########################################################################
 
###########################################################################
# Strompf - [client]
+
# [client]
 
###########################################################################
 
###########################################################################
 
#
 
#
 
# Normally, starting the server takes about a second ("sudo service mysql  
 
# Normally, starting the server takes about a second ("sudo service mysql  
# restart"). Withh these [client] & [mysqldump] sections, this takes about 5
+
# restart"). With these [client] & [mysqldump] sections, this takes about 5
 
# seconds. I still find it handy to put everyting in this one location,
 
# seconds. I still find it handy to put everyting in this one location,
 
# especially when collaborating with others on projects
 
# especially when collaborating with others on projects
#
 
 
#
 
#
 
[client]
 
[client]
Regel 201: Regel 146:
 
#
 
#
 
comments = true
 
comments = true
 +
 +
 +
# local_infile - Allow LOAD DATA - 17 Aug. 2020
 +
###############################################
 +
#
 +
local_infile=ON
  
  
 
###########################################################################
 
###########################################################################
# Strompf - [mysqldump]
+
# [mysqldump]
 
###########################################################################
 
###########################################################################
 
#
 
#
Regel 221: Regel 172:
 
force = true
 
force = true
 
</pre>
 
</pre>
 +
 +
== Conflicten ==
 +
 +
Helaas: Tot op heden (dec. 2021) heb ik nog geen grip op settings: Ik krijg vaak foutmeldingen. Bv. als ik een ''tool'' gebruik dat ik al lang niet heb gebruikt (bv. onlangs met de routines <code>mysqlrepair</code> en <code>mysqloptimize</code>, omdat blijkbaar instellingen voor het ene object (bv. mysqldump) ook wordt toegepast op andere objecten - Wordt vervolgd.
  
 
== Zie ook ==
 
== Zie ook ==
  
* [[Conversie (MySQL)]]
+
* [[Conversie (MySQL) | Conversie]]
 
* [[Error while sending query packet]]
 
* [[Error while sending query packet]]
* [[GROUP CONCAT()-error (MySQL)]]
+
* [[GROUP CONCAT()-error (MySQL) | GROUP CONCAT-error]]
 +
* [[Max allowed packet (MySQL) | Max allowed packet]]
 +
* [[Sort buffer (MySQL) | Sort buffer]]
 +
* [[Systeemvariabelen (MySQL) | Systeemvariabelen]]
 +
* [[Unsafe function declaration (MySQL) | Unsafe function declaration]]

Versie van 28 dec 2021 22:39

In MySQL kun je instellingen configureren per gebruiker, of per systeem. Beiden worden in dit artikel behandeld.

Let op: MySQL is nogal kritisch als het om wijzigingen gaat. Daarom maak ik soms een backup voor ik iets om zeep help. Als het om MySQL-configuratiebestanden gaat, voeg ik een extensie aan het eind toe. Bv. my.cnf.bk01.

.my.cnf

.my.cnf is het configuratiebestand met gebruiker-specifieke instellingen. Dit bestand staat doorgaans direct in je home dir. Mijn versie (licht bijgewerkt, april 2020):

###########################################################################
[Client]
###########################################################################
#
host     = localhost
socket   = /var/run/mysqld/mysqld.sock
user     = supervrouw
password = mijnwachtwoord


# Include comments when inserting sql-dumps
##############################################
#
comments = true


# local_infile - Added Aug. 17, 2020
##########################################
#
local_infile=ON


###########################################################################
[mysqldump]
###########################################################################
#
# Include sprocs & functions when making dumps
##############################################
#
routines = true


# Continue with dump despite errors
##############################################
#
force = true

Maak dit bestand enkel leesbaar voor de eigenaar:

chmod 0600 ~/.my.cnf

Instellingen op serverniveau

Het kan verwarrend zijn waar je systeembrede instellingen moet toepassen, maar ingewikkelder dan dit hoeft 't niet te zijn:

cd /etc/mysql
sudo mv my.cnf my.cnf.bk-org
sudo vim my.cnf
  • Gebruik bestand my.cnf voor eigen instellingen
  • Default-instellingen vind je in /etc/mysql/mysql.conf.d/mysql.cnf - Handig om dingen af te kijken
  • Na aanpassingen moet je de server herstarten, bv. met sudo service mysql restart (niet mysqld)
  • Tot nov. 2020, kopiëerde ik een bestand eerst naar my.cnf, en voegde m'n eigen dingen toe. Dat bleek een foutmelding te geven!

Mijn /etc/mysql/my.cnf (zomer-herfst 2020)

De configuratie op m'n laptop. my.cnf.fallback is een werkende backup. my.cnf is het actuele bestand, en dat vind je hiernaast in detail

Complete bestand:


#  MySQL system-wide configuration file
###########################################################################
#
# * This file contains *only* custom settings
# * Jeroen Strompf - Nov. 2020
# * See http://wiki.devliegendebrigade.nl/Configuratiebestanden_(MySQL)
#   for details
#
#
###########################################################################
# [mysqld]
###########################################################################
#
[mysqld]


# Remove I/O path restrictions
##############################
#
secure_file_priv=""


# Enable longer concat string
#############################
#
group_concat_max_len = 300000


# Disable MySQL Strict Mode
###########################
#
sql_mode=""


# Increase max_packet_size
###########################
#
max_allowed_packet=536870912


# log_bin_trust_function_creators
###################################
#
# * http://wiki.devliegendebrigade.nl/Unsafe_function_declaration_(MySQL)
# * Dit lijkt echter niet te werken (nov. 2020): Zie de URL hierboven
#
log_bin_trust_function_creators = 1;


# local_infile - Allow LOAD DATA - 17 Aug. 2020
###############################################
#
local_infile=ON


###########################################################################
# [client]
###########################################################################
#
# Normally, starting the server takes about a second ("sudo service mysql 
# restart"). With these [client] & [mysqldump] sections, this takes about 5
# seconds. I still find it handy to put everyting in this one location,
# especially when collaborating with others on projects
#
[client]


# Include comments when importing sql-files
####################################################
#
comments = true


# local_infile - Allow LOAD DATA - 17 Aug. 2020
###############################################
#
local_infile=ON


###########################################################################
# [mysqldump]
###########################################################################
#
[mysqldump]


# Include sprocs & functions when making dumps
##############################################
#
routines = true


# Continue with dump despite errors in views
##############################################
#
force = true

Conflicten

Helaas: Tot op heden (dec. 2021) heb ik nog geen grip op settings: Ik krijg vaak foutmeldingen. Bv. als ik een tool gebruik dat ik al lang niet heb gebruikt (bv. onlangs met de routines mysqlrepair en mysqloptimize, omdat blijkbaar instellingen voor het ene object (bv. mysqldump) ook wordt toegepast op andere objecten - Wordt vervolgd.

Zie ook