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:
[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.
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
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
Remove the datadir=/var/lib/mysql
line under [client]
. The client doesn't need to know where the MySQL server is storing data.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments