Taking MySQL DB offline

Taking MySQL Offline the Easy Way: Using ignore-db-dir

A Quick and Simple Way to Take a MySQL Database Offline Without Touching the Data — Perfect for Quick Maintenance and Troubleshooting


The idea for this post came from a client transitioning from SQL Server to MySQL. In SQL Server, taking a database offline is a single command (ALTER DATABASE SET OFFLINE), but MySQL doesn’t have a direct equivalent.

That got me thinking — how can we achieve something similar in MySQL? And that’s where ignore-db-dir comes in.

Sometimes, you need to take a MySQL database offline quickly — maybe to perform maintenance, isolate a corrupted database, or simply prevent access during a critical update. While there are several ways to achieve this, ignore-db-dir stands out as an unconventional but incredibly simple method. It's not the go-to solution for most DBAs, but when you need a quick and reversible way to take a database offline without touching the data, it gets the job done.

Why ignore-db-dir?

Think of ignore-db-dir as a quick, non-destructive way to make a MySQL database temporarily disappear without actually deleting it. As of MySQL 5.7.11 and later, ignore-db-dir allows the target directory to contain other files, such as logs or hidden files (starting with a dot), without causing startup issues. This provides flexibility while still effectively isolating the database. The data remains intact in the filesystem, but MySQL acts as if the database doesn’t exist — making it perfect for quick maintenance or troubleshooting.



How to Use ignore-db-dir

  1. Stop MySQL:
    sudo systemctl stop mysql
  2. Edit the MySQL Configuration:
    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  3. Apply the ignore-db-dir Directive:
    ignore-db-dir = mydatabase
  4. Restart MySQL:
    sudo systemctl start mysql
  5. Verify the Database is Offline:
    SHOW DATABASES;

    Trying to access the ignored database will return:

    ERROR 1049 (42000): Unknown database 'mydatabase'
  6. Bringing the Database Back Online:
    1. Remove the Directive:
      sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
      # ignore-db-dir = mydatabase
    2. Restart MySQL Again:
      sudo systemctl restart mysql
    3. Verify Access:
      USE mydatabase;

      Now, the database will reappear in the list of databases, and you can access it as usual.



When to Use ignore-db-dir (and When Not To)

Use It When:

Avoid It When:



Quick Mentions: Other Ways to Take MySQL Offline

While ignore-db-dir is the quickest and least invasive method, other options include:



Wrapping Up

The ignore-db-dir directive is a hidden gem for anyone looking to temporarily take a MySQL database offline without touching the data. It’s simple, effective, and easily reversible — making it perfect for quick maintenance, troubleshooting, or isolating a problematic database. Just remember to document the change and notify affected teams to avoid confusion. And if you need a more surgical approach, consider the other methods mentioned above.



Hungry for more hands‑on guides on coding, security, and open‑source? Join our newsletter community—new insights delivered every week. Sign up below 👇