查找mysql配置文件,更改其datadir(數據存放路徑)值(筆記)

本文介绍了如何使用`which`命令找到MySQL的安装路径,并通过此路径查找配置文件my.cnf。内容提到了配置文件的读取顺序,包括/etc/mysql/my.cnf、/etc/my.cnf和~/.my.cnf。接着说明了如何打开并编辑my.cnf,特别是更改mysqld.cnf中的datadir值为"/mnt/mysql"。

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

以which命令尋mysql于何處:

which mysql

得徑:

/usr/bin/mysql

以此徑尋配置文件:

/usr/bin/mysql --verbose --help | grep -A 1 'Default options'

顯示信息:

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

其意為: 

服务器先讀/etc/mysql/my.cnf,如不存在則讀/etc/my.cnf,仍不存在則讀~/.my.cnf文件

打開/etc/mysql/my.cnf:疑问除末兩行,他行皆注釋,而我竟不知“!”號何意?

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
尋/etc/mysql/conf.d 無datadir,又尋/etc/mysql/mysql.conf.d

于其中 mysqld.cnf文件見datadir值更為"/mnt/mysql"



























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值