Hoe vind ik de MySQL my.cnf-locatie

Is er een MySQL-opdracht om het configuratiebestand my.cnfte lokaliseren, vergelijkbaar met hoe PHP’s phpinfo()zijn php.inilokaliseert ?


Antwoord 1, autoriteit 100%

Er is geen intern MySQL-commando om dit te traceren, het is een beetje te abstract. Het bestand kan zich op 5 (of meer?) locaties bevinden en ze zouden allemaal geldig zijn omdat ze trapsgewijs laden.

  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • $MYSQL_HOME/my.cnf
  • [datadir]/mijn.cnf
  • ~/.my.cnf

Dit zijn de standaardlocaties waar MySQL naar kijkt. Als het er meer dan één vindt, laadt het ze allemaal & waarden overschrijven elkaar (in de vermelde volgorde, denk ik). Ook kan de parameter --defaults-filehet hele ding overschrijven, dus… in feite is het een enorme pijn in de kont.

Maar omdat het zo verwarrend is, is de kans groot dat het gewoon in /etc/my.cnf staat.

(als je alleen de waarden wilt zien: SHOW VARIABLES, maar u heeft hiervoor de machtigingen nodig.)


Antwoord 2, autoriteit 33%

Je kunt MySQL eigenlijk “opvragen” voor een lijst van alle locaties waar het zoekt naar my.cnf (of my.ini op Windows). Het is echter geen SQL-query. Voer liever uit:

$ mysqladmin --help

of, eerder 5.7:

$ mysqld --help --verbose

In de allereerste regels vindt u een bericht met een lijst van alle my.cnf-locaties waarnaar het zoekt. Op mijn computer is het:

Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/etc/my.cnf
~/.my.cnf

of, op Windows:

Default options are read from the following files in the given order:
C:\Windows\my.ini
C:\Windows\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf

Merk echter op dat het geval is dat er geen my.cnf-bestand is op een van deze locaties . U kunt dus het bestand op uw eigen bestand maken – gebruik een van de monsterconfiguratie-bestanden die bij MySQL Distributie (op Linux – zie /usr/share/mysql/*.cnf-bestanden en -gebruik is afhankelijk Voor u – kopieer het naar /etc/my.cnfen wijzig vervolgens indien nodig).

Merk ook op dat Er ook een opdrachtregeloptie --defaults-fileis die aangepast pad naar My.cnf of My.ini-bestand kan definiëren. Dit is bijvoorbeeld het geval voor MySQL 5.5 op Windows – het wijst naar een My.ini-bestand in de gegevensmap, die normaal niet wordt vermeld met mysqld --help --verbose. Op Windows – zie Service-eigenschappen om uit te zoeken of dit het geval is voor u.

Controleer ten slotte de https: //dev.mySQL. COM / DOC / REFMAN / 8.0 / EN / OPTIE-FISTRIALS.HTML – het wordt daar in meer details beschreven.


Antwoord 3, Autoriteit 11%

U kunt altijd in een terminal uitvoeren.

find / -name my.cnf

Antwoord 4, Autoriteit 5%

U kunt gebruiken:

locate my.cnf
whereis my.cnf
find . -name my.cnf

Antwoord 5, Autoriteit 5%

mysql --help | grep /my.cnf | xargs ls

zal je vertellen waar my.cnfzich bevindt op Mac/Linux

ls: cannot access '/etc/my.cnf': No such file or directory
ls: cannot access '~/.my.cnf': No such file or directory
 /etc/mysql/my.cnf

In dit geval staat het in /etc/mysql/my.cnf

ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf

In dit geval staat het in /usr/local/etc/my.cnf


Antwoord 6, autoriteit 4%

Dit zou kunnen werken:

strace mysql ";" 2>&1  | grep cnf

op mijn machine geeft dit het volgende weer:

stat64("/etc/my.cnf", 0xbf9faafc)       = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4271, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
read(3, "# /etc/mysql/my.cnf: The global "..., 4096) = 4096
stat64("/home/xxxxx/.my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)

Het lijkt er dus op dat /etc/mysql/my.cnf degene is omdat stat64() en read() succesvol waren.


Antwoord 7, autoriteit 2%

Standaard doorzoekt mysql eerst my.cnf in de map /etc. Als er geen /etc/my.cnf-bestand in deze map staat, raad ik u aan om een nieuw bestand in deze map te maken, zoals aangegeven in de documentatie (https://dev.mysql.com/doc/refman/5.6/en/option-files.html).

U kunt ook zoeken naar bestaande my.cnf die is geleverd door uw mysql-installatie. U kunt de volgende opdracht starten

sudo find / -name "*.cnf"

U kunt het volgende configuratiebestand gebruiken met myisam-tabel en zonder innodb mysql-ondersteuning (van poortinstallatie van mysql op mac os x maverick). Controleer elk commando in dit configuratiebestand.

# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /opt/local/var/run/mysql5/mysqld.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port        = 3306
socket      = /opt/local/var/run/mysql5/mysqld.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id   = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/local/var/db/mysql5
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/local/var/db/mysql5
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

Antwoord 8

Zoals opgemerkt door konyak kun je de lijst met plaatsen krijgen waar mysql naar je my.cnf-bestand zal zoeken door mysqladmin --helpuit te voeren. Omdat dit behoorlijk uitgebreid is, kun je snel bij het onderdeel komen waar je om geeft met:

$ mysqladmin --help | grep -A1 'Default options'

Dit geeft een uitvoer vergelijkbaar met:

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

Afhankelijk van hoe je mysql hebt geïnstalleerd, is het mogelijk dat geen van deze bestanden nog aanwezig is. U kunt ze catom te zien hoe uw configuratie wordt gebouwd en uw eigen my.cnfmaken indien nodig op uw gewenste locatie.


Antwoord 9

Voor Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.cnf


Antwoord 10

Ik weet niet hoe je MySQL hebt ingesteld in je Linux-omgeving, maar heb je het gecontroleerd?

  • /etc/my.cnf

Antwoord 11

Probeer mysqld --help --verbose | grep my.cnf | tr " " "\n"

Uitvoer zal zoiets zijn als

/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/etc/my.cnf
~/.my.cnf

Antwoord 12

Als je een Mac gebruikt met Homebrew, gebruik dan

Brouwinfo mysql

Je ziet zoiets als

$ brew info mysql
mysql: stable 5.6.13 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with: mariadb, mysql-cluster, percona-server
/usr/local/Cellar/mysql/5.6.13 (9381 files, 354M) *

Die laatste regel is de INSTALLERDIRper de MySQL-documenten


Antwoord 13

U kunt deze opdracht ook uitvoeren.

mysql --help | grep cnf


Antwoord 14

vond de mijne met

mysqld --help --verbose | grep my.cnf

Antwoord 15

Beantwoord voor alleen MySQL Workbench-gebruikers,


Antwoord 16

Houd er rekening mee dat MARIADDB de configuratiedetails van de verschillende My.CNF-bestanden laadt, zoals vermeld in de andere antwoorden hier, het kan ze ook van andere bestanden met verschillende namen laden.

Dat betekent dat als u een wijziging aanbrengt in een van de MY.CNF-bestanden, het kan worden overschreven door een ander bestand van een andere naam. Om de wijzigingstick te maken, moet u deze in het rechter (het laatst geladen) configuratie-bestand wijzigen – of, misschien, verander deze in alle.

Dus hoe vindt u alle configuratie-bestanden die kunnen worden geladen? In plaats van op zoek naar My.CNF-bestanden, probeer dan:

grep -r datadir /etc/mysql/

Hiermee vindt u alle plaatsen waarin datadir wordt genoemd. In mijn geval produceert het dit antwoord:

/etc/mysql/mariadb.conf.d/50-server.cnf:datadir     = /var/lib/mysql 

Als ik dat bestand (/etc/mysql/mariadb.conf.d/50-server.cnf) bewerk om de waarde voor datadir te wijzigen, werkt het, terwijl het wijzigen in my.cnf dat niet doet. Dus welke optie je ook wilt wijzigen, probeer het op deze manier te zoeken.


Antwoord 17

Een andere optie is om het whereis-commando te gebruiken.

Bijvoorbeeld waar is mijn.cnf


Antwoord 18

Allemaal geweldige suggesties, in mijn geval heb ik het op geen van die locaties gevonden, maar in /usr/share/mysqlheb ik een RHEL VM en heb ik mysql5.5


Antwoord 19

U zult de verschillende locaties moeten bekijken, afhankelijk van uw versie van MySQL.

mysqld --help -verbose | grep my.cnf
For Homebrew:
/usr/local/Cellar/mysql/8.0.11/bin/mysqld (mysqld 8.0.11)
Default possible locations:
/etc/my.cnf
/etc/mysql/my.cnf
~/.my.cnf
Found mine here: 
/usr/local/etc/my.cnf

Antwoord 20

Ik heb de xampp-bundel met apache, php and mysqlgeïnstalleerd in ubuntu. Daar bevindt zich het bestand my.cnfin de map /opt/lampp/etc/. Ik hoop dat het iemand zal helpen.


Antwoord 21

Op Ubuntu (directe bewerking):

$ sudo nano /etc/mysql.conf.d/mysqld.cnf

Antwoord 22

Als je een VPS gebruikt en een my.cnf probeert te bewerken op een al draaiende server, kun je het volgende proberen:

ps aux | grep mysql

U krijgt de parameters te zien waarop het mysql-commando wordt uitgevoerd en waar het --defaults-filenaar verwijst

Houd er rekening mee dat uw server mogelijk meer dan één MySQL/MariaDB-server gebruikt. Als u een regel ziet zonder de parameter --defaults-file, haalt die instantie mogelijk de configuratie op uit de .cnf’s die worden vermeld op mysqladmin --help, zoals anderen al hebben aangegeven uit.


Antwoord 23

Als u MAMP gebruikt, opent u Sjablonen > MySQL (mijn.cnf) > [versie]

Als u MAMP zonder venster gebruikt, moet u mogelijk de werkbalk aanpassen met de knop Aanpassen.


Antwoord 24

voor mij was het dat ik “ENGINE=MyISAM” soort tabellen had, toen ik het eenmaal veranderde in “ENGINE=InnoDB” werkte het 🙂
in PhpMyAdmin op Azure App Service 🙂


Antwoord 25

Het hangt af van uw toegangsrechten, maar voor mij
dit werk op phpmyadmin sql console

TOONT VARIABELEN;

daarna om enkele variabelen te wijzigen
je kunt doen

STEL GLOBALE max_connections = 1000 in;

of

SET @@GLOBAL.max_connections = 1000;

probeer het eens


Antwoord 26

MySQL-configuratiebestand:

/etc/my.cnf

Other episodes