CentOS 6.5下安装官方RPM包的MySQL后找不到my.cnf

在CentOS 6.5中,使用官方RPM包安装mysql-server-5.1.73后发现缺少my.cnf文件。MySQL在没有my.cnf的情况下仍能启动,因为它会使用默认参数或/usr/share/mysql/my-medium.cnf。为解决此问题,可以将my-medium.cnf复制到/etc目录并命名为my.cnf。官方文档建议可以根据需求复制样本配置文件或创建自定义my.cnf来调整服务器设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:CentOS 6.5 64bit

mysql-server版本:mysql-server-5.1.73


使用mysql-server-5.1.73,发现通过yum install mysql-server安装的mysql,没有my.cnf。

[root@localhost deploy]# find / -iname '*.cnf' -print
/etc/pki/tls/openssl.cnf
/usr/local/ssl/openssl.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/doc/mysql-server-5.1.73/my-innodb-heavy-4G.cnf
/usr/share/doc/mysql-server-5.1.73/my-huge.cnf
/usr/share/doc/mysql-server-5.1.73/my-large.cnf
/usr/share/doc/mysql-server-5.1.73/my-small.cnf
/usr/share/doc/mysql-server-5.1.73/my-medium.cnf
/usr/share/doc/kpathsea-2007/kpathsea_defaults/texmf-kpathsea-defaults.cnf
网上看到的解释基本如下:

官方rpm包安装的MySQL默认确实是没有/etc/my.cnf

为什么没有这个文件而MySQL却也能正常启动和使用,这个有两说法:

1my.cnf只是MySQL启动时的一个参数文件,可以没有它,这时MySQL会用内置的默认参数启动;

2MySQL在启动时自动使用/usr/share/mysql/my-medium.cnf文件,这种说法仅限于rpm包安装的MySQL

解决方法很简单,只需复制/usr/share/mysql/my-medium.cnf文件到/etc目录,并改名为my.cnf即可:

cp/usr/share/mysql/my-medium.cnf /etc/my.cnf


我的设定方式:

[root@localhost deploy]# mkdir /etc/mysql/
[root@localhost deploy]# cp /usr/share/mysql/my-medium.cnf /etc/mysql/my.cnf

从MySQL官网看到的两部分说明如下:

https://dev.mysql.com/doc/refman/5.5/en/data-directory-initialization.html

If you installed MySQL using a source distribution, you may want to optionally copy one of the provided configuration files from the support-files directory into your /etc directory. There are different sample configuration files for different use cases, server types, and CPU and RAM configurations. To use one of these standard files, copy it to /etc/my.cnf, or /etc/mysql/my.cnf and edit and check the configuration before starting your MySQL server for the first time.

如果您使用源代码发行版来安装MySQL,则可能需要将提供的配置文件中的一个从support-files目录复制到/ etc目录中。 不同的用例,服务器类型,CPU和RAM配置有不同的示例配置文件。 要使用这些标准文件之一,请将其复制到/etc/my.cnf或/etc/mysql/my.cnf,并在首次启动MySQL服务器之前编辑并检查配置。

You can also create my.cnf yourself and place into it the options the server should use at startup. See Section 5.1.2, “Server Configuration Defaults”.

您也可以自己创建my.cnf,并在启动时将服务器应该使用的选项放入其中。 请参见第5.1.2节“服务器配置默认值”。

If you do not copy one of the standard configuration files or create your own, the MySQL server starts with its default settings.

如果您不复制其中一个标准配置文件或创建自己的配置文件,MySQL服务器将以其默认设置启动。


https://dev.mysql.com/doc/refman/5.5/en/server-configuration-defaults.html

MySQL provides a number of preconfigured option files that can be used as a basis for tuning the MySQL server. Look for files named my-small.cnfmy-medium.cnfmy-large.cnf, and my-huge.cnf, which are sample option files for small, medium, large, and very large systems. On Windows, the extension is .ini rather than .cnf.

MySQL提供了一些预配置的选项文件,可以作为调整MySQL服务器的基础。 查找名为my-small.cnf,my-medium.cnf,my-large.cnf和my-huge.cnf的文件,这些文件是小型,中型,大型和超大型系统的示例选项文件。 在Windows上,扩展名是.ini而不是.cnf。

For a binary distribution, look for the sample files in or under your installation directory. If you have a source distribution, look in the support-files directory. To use a sample file as a base configuration file, rename a copy of it and place the copy in the appropriate location. Regarding names and appropriate location, see the general information provided in Section 4.2.6, “Using Option Files”. That section also describes option file format and syntax.

对于二进制发行版,请查找安装目录下或安装目录下的示例文件。 如果你有一个源代码发行版,请查看support-files目录。 要将示例文件用作基本配置文件,请重命名该文件的副本并将副本放在适当的位置。 有关名称和适当的位置,请参见第4.2.6节“使用选项文件”中提供的一般信息。 该部分还介绍了选项文件格式和语法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值