Skip to content
www.mytechnote.ru
Menu
  • Administration
    • Scripts
  • Equipment
    • Reviews
    • Instructions
  • Other
  • English
    • English
    • Русский
Menu

How to Quickly Delete All MySQL Databases

Ever needed to delete all databases in MySQL? I recently faced this challenge. With a vast number of databases, manually deleting each one was daunting and time-consuming. But don’t fret, I’ve discovered an efficient command that makes this task a breeze.

Streamlining MySQL Database Deletion:

The Lifesaver Command:

mysql -uroot -p<password> -e "show databases" | grep -v Database | grep -v mysql | grep -v information_schema | gawk '{print "drop database " $1 ";select sleep(0.1);"}' | mysql -uroot -p<password>

Replace <password> with your actual MySQL password.

This powerful command eradicates all databases on your server, sparing mysql and information_schema. If you wish to retain specific databases, simply append | grep -v your_database_name after grep -v mysql| grep -v information_schema|.

Note: For this command to work, it’s essential to have gawk installed. If you’re on Ubuntu and don’t have it, here’s how to get it:

apt update
apt install gawk

Managing MySQL databases doesn’t have to be tedious. With the right commands, you can expedite processes and manage your databases efficiently.

Posted on 08.09.201730.05.2024 by sanglyb

Post navigation

← Solving the ‘failed to open statefile /var/run/network/ifstate: No such file or directory’ Error on a Debian Server
Automating LXC Container Backups: A Step-by-Step Guide →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Подписывайтесь

Youtube
vk
telegram
github
twitter
rss
  • Форум
  • Об авторе
  • Поддержать автора

Популярные записи

Новые записи

  • How to Extend an LVM Partition in Linux
  • SCCM Reporting Errors After Migrating from SQL Server 2016 to 2019
  • Problem Using PassFiltEx on Older CPUs
  • How to remove attachments from old calendar events in Exchange using a script
  • How to download and install Office 2024 LTSC

Архивы

  • 2026 (3)
  • 2025 (5)
  • 2024 (7)
  • 2023 (30)
  • 2022 (4)
  • 2020 (17)
  • 2017 (82)
  • 2016 (5)
© 2015-2026 www.mytechnote.ru
Использование материалов сайта возможно только с разрешения владельца или обязательна индексируемая, прямая, передающая вес ссылка на материал.