2010-03-20 116 views

回答

392

沒有內部的MySQL命令來跟蹤它,它有點太抽象了。該文件可能位於5個(或更多?)位置,並且它們都將是有效的,因爲它們會加載級聯。

  • 的/etc/my.cnf
  • /etc/mysql/my.cnf
  • $ MYSQL_HOME/my.cnf中
  • [DATADIR] /my.cnf
  • 〜/。我的。 cnf

這些是MySQL查看的默認位置。如果它發現不止一個,它將加載它們中的每一個&值互相覆蓋(按照列出的順序,我認爲)。此外,--defaults-file參數可以覆蓋整個事物,所以...基本上,這是一個巨大的痛苦。

但是,由於它很混亂,很可能它只是在/etc/my.cnf中。

(如果你只是想看到的值:SHOW VARIABLES,但你需要的權限,這樣做)。

+0

https://dev.mysql.com/doc/refman/5.1/en/option-files.html – 2014-02-22 13:55:03

+0

'MySQL的:未知變量「默認文件= ...' – Cerin 2014-04-30 22:38:10

+4

確保編輯我後重新啓動MySQL服務器。 cnf:'/etc/init.d/mysqld restart'。 – Danijel 2014-11-24 15:44:39

3

我不知道你是如何在你的Linux環境中設置MySQL的,但是你檢查過了嗎?

  • 的/etc/my.cnf
37

你總是可以找到運行在終端。

find/-name my.cnf 
+0

它的硬盤的方式:( 有沒有喜歡的phpinfo任何mysql命令()知道配置文件位置? – robinmag 2010-03-20 18:13:04

+0

'找到/ -name my.cnf'是你最好的選擇,但你可以還要檢查你的主目錄和/etc/mysql/my.conf 你也可以通過在終端 – Dyllon 2010-03-20 20:58:22

+5

中輸入'echo $ MYSQL_HOME'來查看你的MYSQL_HOME是否設置好了,這在大多數機器上都是永久的。定位安裝,只要updatedb的定期運行,你可以做: 找到my.cnf文件|少 – 2010-03-21 02:36:33

17

這可能會實現:

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

我的機器這個輸出上:

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) 

所以看起來/etc/mysql/my.cnf是因爲它stat64中的一個()和read()是成功的。

136

實際上,您可以讓MySQL向您顯示它搜索my.cnf(或Windows上的my.ini)的所有位置的列表。但它不是一個SQL命令。相反,執行:

$ mysqld --help --verbose 

在第一行中,您將找到一條包含所有my.cnf位置列表的消息。在我的機器,它是:

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 

或者,在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 

不過請注意,這它可能是有在這些位置沒有my.cnf文件。因此,您可以自行創建文件 - 使用MySQL發行版提供的示例配置文件之一(在Linux上 - 請參閱/usr/share/mysql/*.cnf文件並使用適合您的文件 - 將其複製到/etc/my.cnf,然後根據需要進行修改)。

另外,請注意,還有一個命令行選項--defaults-file它可以定義到my.cnf或my.ini文件的自定義路徑。例如,Windows上的MySQL 5.5就是這種情況 - 它指向數據目錄中的my.ini文件,通常不會與mysqld --help --verbose一起列出。在Windows上 - 查看服務屬性以查明這是否屬於您。

最後,檢查http://dev.mysql.com/doc/refman/5.5/en/option-files.html - 它在那裏有更詳細的描述。

編輯2017年 - MySQL的5.7+

在MySQL 5.7用途:

mysqladmin --help 
+0

看起來很有希望,但在我的發行版(opencsw.org)上,沒有mysqld。它運行mysqld_safe。 「mysqld_safe --verbose --help」無法識別。 – 2012-03-28 14:24:38

+0

當我運行它,我得到這個:'默認選項從給定的順序讀取下列文件: /etc/mysql/my.cnf /etc/my.cnf〜/ .my.cnf' - 我期望前兩個文件的順序相反。 – yitwail 2013-02-28 22:57:20

+0

'mysqld --help --verbose'發佈的信息違反了http://dev.mysql.com/doc/refman/5.5/en/option-files.html中陳述的內容。在5.6版本的「最近的今天」體驗中,網站中的信息是最正確和最相關的。幫助命令給出的文件位置的優先級是誤導性的,會導致負面結果。 – 2013-12-01 10:53:55

2

另一種選擇是使用因此whereis命令。

E.g. whereis的my.cnf

+1

如果系統支持「定位」,你可能會更好。 – drobert 2013-04-09 14:04:27

26

您可以使用:

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

偉大的地方是在Ubuntu 12.0.1的/etc/mysql/my.cnf上EC2 – Maziyar 2013-05-28 02:02:04

+0

'whereis'在這裏不起作用;它搜索對應於*命令*的位置,並且找不到任意文件。 – 2015-11-10 12:05:19

+0

而updatedb的更新列表中找到經歷 - 如果my.cnf中沒有收錄 – WoodyDRN 2017-05-03 22:15:06

4

如果你有家釀在Mac上,使用

沖泡信息mysql的

你會看到什麼像

$ 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) * 

最後一行是INSTALLERDIRper the MySQL docs

9

默認情況下,mysql首先在/ etc文件夾中搜索my.cnf。如果此文件夾中沒有/etc/my.cnf文件,我建議您在此文件夾中創建一個新文件夾(https://dev.mysql.com/doc/refman/5.6/en/option-files.html)。

您還可以搜索由您的mysql安裝提供的現有my.cnf。您可以啓動下面的命令

sudo find/-name "*.cnf" 

您可以使用下面的配置文件,MyISAM表,並沒有InnoDB的MySQL的支持(從口安裝MySQL的Mac OS X上特立獨行的)。請驗證此配置文件中的每個命令。

# 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 
1

所有偉大的建議,在我來說,我沒有發現它在這些地區,但在/usr/share/mysql,我有一個RHEL虛擬機,我裝mysql5.5

0

我安裝了XAMPP束與apache, php and mysqlubuntu。有my.cnf文件位於/opt/lampp/etc/文件夾中。希望它能幫助別人。

6

正如konyak指出的那樣,您可以通過運行mysqladmin --help來獲取mysql將查找您的my.cnf文件的位置列表。由於這是非常詳細,你可以得到的一部分,你很快關心與:

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

這會給你的輸出類似於:

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 

取決於你如何安裝的MySQL有可能是沒有這些文件還沒有出現。您可以通過cat來查看您的配置是如何構建的,並根據需要在您的首選位置創建您自己的my.cnf

4

嘗試運行mysqld --help --verbose | grep my.cnf | tr " " "\n"

輸出將會像

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

找到礦用

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

對於Ubuntu的16:/etc/mysql/mysql.conf.d/mysqld。 CNF

+0

如果你想改變mysql的配置在Ubuntu 16.04 編輯以下文件 '對於Ubuntu的16:在/ etc/mysql的/ MySQL的。 conf.d/mysqld.cnf' – 2017-07-05 08:49:21

0

回答只有MySQL工作臺用戶,

enter image description here

0

如果使用的是甲基苯丙胺,訪問模板>的MySQL(my.cnf中)> [版本]

如果您正在運行MAMP窗戶,你可能需要自定義使用自定義工具欄按鈕。

MAMP PRO Templates Menu