是否有一个MySQL命令来定位my.cnf
配置文件,类似于PHP'的phpinfo()
定位其php.ini
?
没有内部的MySQL命令来追踪这一点,这有点太抽象了。 文件可能在5个(或更多?)位置,它们都将是有效的,因为它们是逐级加载的。
这些是MySQL查看的默认位置。 如果它发现不止一个,它将加载它们中的每一个&;值会覆盖彼此(按照列出的顺序,我想)。 另外,--defaults-file
参数可以覆盖整个事情,所以......基本上,它是一个巨大的麻烦。
但是,由于它是如此混乱,很有可能它只是在/etc/my.cnf中。
(如果你只想看数值。SHOW VARIABLES
,但你需要有权限才能这样做)。)
实际上你可以"请求"。 MySQL中搜索my.cnf(或Windows上的my.ini)的所有位置的列表。 不过这不是一个SQL查询,而是执行:"request&ot;MySQL搜索my.cnf的所有位置(或Windows上的my.ini)的列表。 而是执行。
$ mysqladmin --help
或者,在5.7之前。
$ 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
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上--查看服务属性,找出你的情况是否如此。
最后,查看https://dev.mysql.com/doc/refman/8.0/en/option-files.html - 那里有更详细的描述。
您可以使用 。
locate my.cnf
whereis my.cnf
find . -name my.cnf
这可能有用
strace mysql ";" 2>&1 | grep cnf
在我的机器上,这个输出是:{{{6719635}}。
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()都成功了。
默认情况下,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"
你可以使用下面的配置文件,在没有innodb mysql支持的情况下使用myisam表(从mac os x maverick的mysql端口安装)。 请验证这个配置文件中的每一条命令。
# 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
正如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的方式,有可能这些文件都还不存在。 你可以 "猫 "它们,以便查看你的配置是如何建立的,如果需要的话,可以在你的首选位置创建你自己的 "my.cnf"。
mysql --help | grep /my.cnf | xargs ls
会告诉你Mac/Linux上my.cnf
的位置。
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
在这种情况下,它在/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
在这种情况下,它在/usr/local/etc/my.cnf
中。
如果你在Mac上使用Homebrew,请使用
酝酿信息 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) *
最后一行是INSTALLERDIR
根据MySQL文档
你必须根据你的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