无法使用 mysqldump 导出数据库:未知变量 'datadir=/var/lib/mysql' [英] Cannot export database with mysqldump: unknown variable 'datadir=/var/lib/mysql'
问题描述
尝试导出数据库时:
mysqldump -u root -p --opt databasename > databasename.sql
它失败并显示:
mysqldump: unknown variable 'datadir=/var/lib/mysql'
<小时>
上网查了一下,发现mysql配置文件有:
I researched on internet and found cases where the mysql configuration file had:
[mysqldump]
datadir=/var/lib/mysql
在这些情况下,解决方案是删除 [mysqldump]
/datadir
变量,但在我的情况下,我的任何配置文件中都没有该变量,因此该解决方案对我没有用.
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.
为了查看所有可能的配置文件在我的系统中的位置,我使用了mysqld --verbose --help
,结果显示:
To see where all the possible configuration files are located in my system, I used mysqld --verbose --help
, and the result showed:
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
其中一些配置文件不存在,存在的甚至没有[mysqldump]
变量组,例如我的/etc/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:
[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?
推荐答案
[client]
datadir=/var/lib/mysql
删除 [client]
下的 datadir=/var/lib/mysql
行.客户端不需要知道 MySQL 服务器在哪里存储数据.
Remove the datadir=/var/lib/mysql
line under [client]
. The client doesn't need to know where the MySQL server is storing data.
这篇关于无法使用 mysqldump 导出数据库:未知变量 'datadir=/var/lib/mysql'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!