Mysqldump got error 1049 unknown database mysqldump when selecting the database

The "MySQLdump: got error :1049 :unknown database " triggers while performing cPanel backups. This can happen when the database does not exist in MySQL

Often while performing WHM backups, users notice an error “mysqldump: Got error: 1049: Unknown database”. This can happen when the database does not exist in MySQL.

As a part of our Server Management Services, we help our customers with similar requests related to WHM/ cPanel.

Let us today, discuss the possible reasons and fixes for this error.

What causes “MySQLdump: got error :1049 :unknown database ” error

MySQLdump helps to perform the logical backups, generating a set of SQL statements like DDL, DML for reproduced backup Schema. It dumps one or more MySQL databases for backup or transfers to another SQL server.

We can also generate output in CSV, other delimited text or XML format. The main drawback of MySQLdump is that the restoration procedure can take a long time to execute if the database is very large.

While performing WHM backups, at times, we can see the following error in the backup log:

The backup process encountered the following error: The backup process on “hostname.example.server” encountered an error.
[2021-05-10 02:25:26 -0600] mysqldump: Got error: 1049: Unknown database ‘example_database’ when selecting the database

Generally, This error indicates that the related database exists in a cPanel user’s database map, but the database does not exist in MySQL.
 

How to fix “MySQLdump: got error :1049 :unknown database ” error

The first thing that our Support Engineers perform on seeing this error is to check whether the database exists within MySQL. They does this by running the following command as the root user via SSH:

mysql -e "show databases;" | grep example_database

Replace example_database with the database found within the backup error in the backup logs. We can find the backup logs within /usr/local/cpanel/logs/cpbackup.

If the above command does not display any results, it indicates that the database does not exist in MySQL.

Thus, In order to correct the backup errors, we have to remove the databases that do not actually exist in MySQL from cPanel.

For this, we initially log in to the cPanel account for the particular database user. Then, we navigate to the Databases section and then click on the MySQL Databases option.

Here, we just need to delete the corresponding database from the current database section.

mysqldump got error 1049 unknown database

 
[Need any further assistance to fix cPanel errors? – We’re available 24*7]

Conclusion

The “MySQLdump: got error :1049 :unknown database ” triggers while performing cPanel backups. This can happen when the database does not exist in MySQL. Today, we saw how our Support Engineers fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

I need to get a DBDUMP, i am using MySQL.
I get the following error when i try to get a DB Dump. Any clue what it did wrong.

C:Program FilesMySQLMySQL Server 5.1bin>mysqldump -u root -p xxx myDB
e >  dump.sql
Enter password: ***
mysqldump: Got error: 1049: Unknown database 'xxx' when selecting the database

asked Aug 4, 2012 at 18:23

Illep's user avatar

That command is saying you want to enter the password at the prompt and dump the myDB table from the xxx database. If you get rid of the «xxx» part and enter the password at the prompt, it should work.

If you actually want to specify the password on the command line, you have to do -pWHATEVER (where «WHATEVER» is the literal password, with no space after the switch), or --password=WHATEVER, but:

Specifying a password on the command line should be considered insecure.

Documentation link

Jess Stone's user avatar

answered Aug 4, 2012 at 18:32

JMM's user avatar

JMMJMM

25.4k3 gold badges50 silver badges55 bronze badges

you should delete the xxx behind the -p , because the is type int the next line at the Enter password, and you should write your database name.

answered Sep 28, 2013 at 3:04

bin's user avatar

If you want to avoid warning «Specifying a password on the command line should be considered insecure.» just use option —defaults-extra-file

For example:

/usr/bin/mysqldump --defaults-extra-file=/tmp/auth.tmp --user=xxx --tables dbname  --host localhost

Where /tmp/auth.tmp content is

[client]
password=yyyy

answered Apr 12, 2016 at 10:48

Matej Pončák's user avatar

If you use localhost with basic user=root,password=<blank> just copy this mysqldump -d -u root -l dbname

answered Jun 7, 2017 at 18:29

zey_ser's user avatar

zey_serzey_ser

1452 silver badges11 bronze badges

Based on your comments below your question, it sounds like you probably omitted the --databases option when you used mysqldump to backup the database.

If you backup the databases by doing mysqldump <database-name>, then the backup does not re-create the database for you. When you restore from that backup, you need to create the database that you want to import into and then import into that database, which may or may not be the same name as the database you exported from earlier.

If you do not want to be required to do this, then, when creating your backup, you export like this: mysqldump --databases <database-name>. Doing that, the backup will have the command to re-create the database when it is imported back into MySQL.

There are also other differences between those two usages. If you use the first version, then any symbols after the database name are considered table names to include in the backup. As in: mysqldump MyDatabase Table1 Table2 Table3 to backup tables 1, 2, and 3, but no others.

In the second variation, all symbols after the initial database name are also treated as additional database names, so you can get multiple databases. mysqldump --databases HRDatabase WebsiteDatabase DevTestDatabase That should export all three databases.

But back to the main point: next time you use mysqldump, if you specify the --databases option then you will not need to manually create the database and use it before importing, as that would then be taken care of for you.


For importing the database you need to use mysql not mysqldump in order to create the database automatically (only in case you exported with --databases <database-name> option:
mysql -u root -p < /var/www/html/example.com/backups/backup.sql
(as mentioned in a previous comment by HBruijn,

Using mysqldump for importing your database will not create your database automatically even if you exported it with --databases <database-name> option, these will not work without creating the database first:

mysqldump -u root -p < /var/www/html/example.com/backups/backup.sql
mysqldump --all-databases -u root -p < /var/www/html/example.com/backups/backup.sql
mysqldump --databases mydatabase_name -u root -p < /var/www/html/example.com/backups/backup.sql

Понравилась статья? Поделить с друзьями:
  • Mysql ошибка 1418
  • Mudrunner ошибка could not load config steam
  • Mysql ошибка 1415
  • Mssql skip error
  • Mysql как изменить длину поля