无法导出带有mysqldump的数据库:未知变量'datadir=/var/lib/mysql'

时间:2021-11-02 23:18:08

When trying to export a database with:

当尝试导出数据库时:

mysqldump -u root -p --opt databasename > databasename.sql

It fails and shows:

它失败,显示:

mysqldump: unknown variable 'datadir=/var/lib/mysql'

I researched on internet and found cases where the mysql configuration file had:

我在互联网上搜索,发现mysql配置文件有:

[mysqldump]
datadir=/var/lib/mysql

In those cases the solution was to delete that [mysqldump]/datadir variable, but in my case I didn't have that variable in any of my configuration files, hence that solution wasn't useful for me.

在这些情况下,解决方案是删除[mysqldump]/datadir变量,但是在我的例子中,我的任何配置文件中都没有这个变量,因此这个解决方案对我来说都没有用处。


To see where all the possible configuration files are located in my system, I used mysqld --verbose --help, and the result showed:

为了查看系统中所有可能的配置文件的位置,我使用了mysqld——verbose——帮助,结果显示:

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

Some of these configuration files don't exist, and the ones that exist doesn't even have the [mysqldump] variable-group, for example my /etc/my.cnf has:

有些配置文件不存在,而存在的配置文件甚至没有[mysqldump]变量组,例如my /etc/my.cnf有:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-storage-engine=MyISAM
innodb_file_per_table=1
max_allowed_packet=268435456
local-infile=0
max_connections=1024
table_definition_cache=400
performance_schema=0
open_files_limit=10000

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

Then what's the cause and solution?

那么原因和解决办法是什么呢?

1 个解决方案

#1


2  

[client]
datadir=/var/lib/mysql

Remove the datadir=/var/lib/mysql line under [client]. The client doesn't need to know where the MySQL server is storing data.

删除[client]下的datadir=/var/lib/mysql行。客户端不需要知道MySQL服务器存储数据的位置。

#1


2  

[client]
datadir=/var/lib/mysql

Remove the datadir=/var/lib/mysql line under [client]. The client doesn't need to know where the MySQL server is storing data.

删除[client]下的datadir=/var/lib/mysql行。客户端不需要知道MySQL服务器存储数据的位置。