Cannot export database with mysqldump: unknown variable 'datadir=/var/lib/mysql'

mikl

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?

duskwuff -inactive-
[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.

edited at
0

Comments

0 comments
Login to comment

Related

mysqldump cannot backup database

How to fix the error "unknown variable datadir" in mysql on raspbian?

mysqldump unknown database bitnami_redmine

Export an AWS Aurora Serverless MySQL database with mysqldump

Mysqldump - Error 1049 unknown database [db] when selecting the database

How to export WebSQL database to .sql file? (like mysqldump)

mysqldump: [ERROR] unknown variable 'delayed-insert=FALSE'

MySQLdump backup script no longer works, getting "mysqldump: unknown variable 'local-infile=0'"

Cannot export Azure SQL database

mysql database missing due to datadir change

Firebase Realtime database rules "Unknown variable 'request'."

Cannot export or set variable in new shell

Cannot export variable thanks to a script with zsh

mysqldump with php to export a single table

mysqldump a database with condition on tables

Slow restore of database mysqldump

Cannot create PoolableConnectionFactory (Unknown database 'XYZ_DEV')

'unknown option -W' error when running mysqldump

Slow write of database using `mysqldump `

How to change mysqldump USE DATABASE

mysqldump - Export structure only without autoincrement

Use mysqldump to export data that is compatible with older versions

Android SQLite Database "R cannot be resolved to a variable"

Unknown variable +

Unknown pseudo selector 'export' in WebStorm

Can I dump database with mysql (not mysqldump)?

Is it possible to put database in the cnf file To secure mysqldump

How to make mysqldump work well for a WordPress database?

mysqldump dump only database with certain prefix