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.
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.
ignore-db-dir
sudo systemctl stop mysql
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
ignore-db-dir
Directive:
ignore-db-dir = mydatabase
sudo systemctl start mysql
SHOW DATABASES;
Trying to access the ignored database will return:
ERROR 1049 (42000): Unknown database 'mydatabase'
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# ignore-db-dir = mydatabase
sudo systemctl restart mysql
USE mydatabase;
Now, the database will reappear in the list of databases, and you can access it as usual.
ignore-db-dir
(and When Not To)While ignore-db-dir
is the quickest and least invasive method, other options include:
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 👇