Mysqlcheck got error 1049 unknown 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»;

This document (7009762) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 10 Service Pack 1

SUSE Linux Enterprise Server 10 Service Pack 2

SUSE Linux Enterprise Server 10 Service Pack 3

SUSE Linux Enterprise Server 10 Service Pack 4

SUSE Linux Enterprise Server 11 Service Pack 1

SUSE Linux Enterprise Server 11 Service Pack 2

Situation

ERROR 1049 (42000): Unknown database ‘mysql’ when trying to access mysql via this command:

this command will access the default ‘mysql’ database, and needs to be done prior to setting or resetting the root users’ MySQL password.

Resolution

Depending on how MySQL was installed, it is possible that the default MySQL database was NOT created. 

This may be checked by looking in /var/lib/mysql for a mysql subfolder (i.e. /var/lib/mysql/mysql ). If the path does NOT contain a mysql subfolder, it needs to be created by completing the following steps:
 

rcmysql stop
pkill mysql   (NOTE: wait until notification is given that mysqld ended, then hit <ENTER>)
/usr/bin/mysql_install_db

Now that the above steps have been run, check and make sure that the database was created:
 

cd /var/lib/mysql
ls -al | grep mysql

In the listing output there should now be a folder called mysql.  Finally, the correct owner and group need to be set on the mysql folder.

Restart the mysql service in safe mode again and attempt the initial command again:

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented «AS IS» WITHOUT WARRANTY OF ANY KIND.

  • Document ID:7009762
  • Creation Date:
    17-Nov-2011
  • Modified Date:12-Aug-2022
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

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

  • Печать

Страницы: [1]   Вниз

Тема: не стартует mysql  (Прочитано 3534 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн
DimmKo

Добрый день.
Случилась неприятность: не стартует mysql. Ubuntu (x86_64) 14.04.4 LTS.
Всё было нормально, провел обновление apt-get update && apt-get upgrade (mysql не обновлялся), всё прошло штатно без ошибок, перезапустил сервер.
При загрузке написал, что starting mysql — failed.
Запускаю руками и вижу вот такое дело:

и ничего не происходит. Нажимаю CTRL + C, делаю service mysql start —> OK | service mysql status mysql start/running, process 29726
далее, хочу сделать дамп БД, на что получаю вот такую ошибку:

Попробовал поиска в гугле ошибку, но что нашел не подходит. Не могу понять в чем дело.
Логи:
1) /var/log/mysql/error

2) /var/log/syslog

Может дополнительно какие-то логи надо добавить.

Может кто знает, что я упустил из виду, для решения это проблемы?
Спасибо.

Ubuntu Server 20.04.2 LTS | x86_64


Оффлайн
lAionl

Бегло ознакомившись с текстом:

Checking for tables which need an upgrade, are corrupt or were
not closed cleanly.

могу сказать, что нужно чинить ^_^:

mysqlcheck --check-upgrade --all-databases --auto-repair -u root -p
mysql_upgrade --force -u root -p
P.S. если пока я иду разогревать обед, вы воспользовавшись этими командами убьете содержимое БД, я снимаю с себя ответственность за это. Перед вводом команд, убедитесь что имеется резервная копия данных.

« Последнее редактирование: 11 Марта 2016, 11:01:24 от lAionl »

Asus K53SV,i7-2670QM,16Gb RAM, GT540M, 3.18.11-gentoo.


Оффлайн
DimmKo

lAionl,
добрый день, спасибо за ваш совет, но что-то пошло не так ^_^
Enter password:
mysqlcheck: Got error: 1049: Unknown database ‘—check-upgrade’ when selecting the database

Ubuntu Server 20.04.2 LTS | x86_64


Оффлайн
lAionl

Исправил команды в ответе выше, попробуйте.

Asus K53SV,i7-2670QM,16Gb RAM, GT540M, 3.18.11-gentoo.


Оффлайн
DimmKo

lAionl,
благодарю…
1) команду запустил… появилось много «ОК», а закончилось вот этим
mysqlcheck: Got error: 2013: Lost connection to MySQL server during query when executing ‘CHECK TABLE …  FOR UPGRADE’

вторую команду стоит ли запускать?

Ubuntu Server 20.04.2 LTS | x86_64


Оффлайн
lAionl

Попробуйте.

mysqlcheck --all-databases --repair --analyze --optimize --auto-repair

Asus K53SV,i7-2670QM,16Gb RAM, GT540M, 3.18.11-gentoo.


Оффлайн
DimmKo

Попробуйте.
mysqlcheck --all-databases --repair --analyze --optimize --auto-repair

Error:  mysqlcheck doesn’t support multiple contradicting commands.

Ubuntu Server 20.04.2 LTS | x86_64


Оффлайн
lAionl

mysqlcheck --all-databases --repair --analyze --optimize

Asus K53SV,i7-2670QM,16Gb RAM, GT540M, 3.18.11-gentoo.


Оффлайн
DimmKo

lAionl,
та же ошибка
попробовал вот это

mysqlcheck --all-databases --optimize --auto-repair -u root -pвыдало значения по одной базе

и закончилось вот этим
mysqlcheck: Got error: 2013: Lost connection to MySQL server during query when executing ‘OPTIMIZE TABLE … ‘

может удалить эту базу?

Ubuntu Server 20.04.2 LTS | x86_64


Оффлайн
lAionl

нужно запустить  mysql и передать как параметр —net_read_timeout=6000, затем повторить самую первую команду которую вводили (самый первый ответ)

Asus K53SV,i7-2670QM,16Gb RAM, GT540M, 3.18.11-gentoo.


Оффлайн
DimmKo

нужно запустить  mysql и передать как параметр —net_read_timeout=6000, затем повторить самую первую команду которую вводили (самый первый ответ)

сделал /etc/init.d/mysql start —net_read_timeout=6000
запустился так же с кучей ошибок.
Выполнил команду из вашего 1-го ответа:
mysqlcheck: Got error: 2013: Lost connection to MySQL server during query when executing ‘CHECK TABLE …  FOR UPGRADE’

Может удалить нафиг, да и заново поставить?

Ubuntu Server 20.04.2 LTS | x86_64


Оффлайн
lAionl

Может удалить нафиг, да и заново поставить?

Можно попробовать.

Asus K53SV,i7-2670QM,16Gb RAM, GT540M, 3.18.11-gentoo.


Оффлайн
DimmKo

lAionl,
спасибо за вашу помощь.

Решение:
удалил (правда через webmin) всё что связано с mysql:

потом папки удалил (/etc/mysql | /var/lib/mysql)
потом перезагрузился и заново установил.
Залил дампы баз обратно — всё корректно работает.

Ubuntu Server 20.04.2 LTS | x86_64


  • Печать

Страницы: [1]   Вверх

Понравилась статья? Поделить с друзьями:
  • Mysqladmin connect to server at localhost failed error access denied for user root localhost
  • Mysql2 error connectionerror access denied for user root localhost using password no
  • Mysql таблица используется ошибка
  • Mysql ошибка при импорте
  • Mysql ошибка 2013