Linux 下如何查找 MySQL 数据库的数据根目录呢?

笔者的服务器系统和MySQL版本如下:

[root@htlwk0001host ~]# mysql -V
mysql  Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using  EditLine wrapper
[root@htlwk0001host ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core) 

MySQL 的配置文件路径是 /etc/my.cnf,那么我们就查看这个配置文件的内容:

[root@htlwk0001host ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

lower_case_table_names=1

character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

#skip-grant-tables

[client]
default-character-set=utf8mb4
#default-character-set=gbk
[mysql]
default-character-set=utf8mb4
#default-character-set=gbk
[mysqld]
#default-character-set=gbk
secure-file-priv=''

在配置文件中,可以看到 datadir=/var/lib/mysql,所以数据库的数据根目录就是 /var/lib/mysql

我们可以查看 /var/lib/mysql 目录下的内容:

[root@htlwk0001host ~]# ls /var/lib/mysql
auto.cnf      ca-key.pem  client-cert.pem  ib_buffer_pool  ib_logfile0  ibtmp1  mysql.sock       mysql_upgrade_info  private_key.pem  public_key.pem  server-cert.pem  sys   zentao
binlog.index  ca.pem      client-key.pem   ibdata1         ib_logfile1  mysql   mysql.sock.lock  performance_schema  production       qydpw           server-key.pem   test

每个数据库(除了information_schema)对应的物理目录文件都在里面。

上一篇:自定义跳出多层循环


下一篇:wasm-pack 编译错误 unexpected character '\u{0}'