Ignoring the lost+found Directory in your Datadir

I still get asked about the lost+found directory enough, and so I wanted to provide a current update.

The lost+found directory is a filesystem directory created at the root level of a mapped drive. Thus this is common to see if you create your mysql datadir at the root level of a mapped drive.

In the past, you could ignore it, if it wasn’t too problematic for you, or you could move your datadir down a level, and then it wouldn’t be created in the datadir anymore.

However, there is now the –ignore-db-dir option. It is actually not too new (it’s been in MariaDB since 5.3.9 and 5.5.28, and in MySQL as of 5.6.3), but I don’t think many are too familiar with it.

But when you do run into this problem, some/many would prefer to add a single line to the config file rather than move the datadir.

To do this, just add the following option to your my.cnf file, under the [mysqld] section (it cannot be set dynamically):

ignore-db-dir=lost+found

And just to show the example:

Before updating my.cnf file:

mysql> select version();
+--------------------+
| version()          |
+--------------------+
| 5.5.40-MariaDB-log |
+--------------------+

mysql> show global variables like 'ignore_db_dirs';
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| ignore_db_dirs |       |
+----------------+-------+

Update my.cnf file and restart mysqld:

mysql> show global variables like 'ignore_db_dirs';
+----------------+------------+
| Variable_name  | Value      |
+----------------+------------+
| ignore_db_dirs | lost+found |
+----------------+------------+

mysql> use lost+found
ERROR 1102 (42000): Incorrect database name 'lost+found'

Now you see the lost+found directory is ignored now.

Of course, you can omit multiple directories. However, if you need to add more than one, then you *must* use multiple instances of the ignore_db_dirs= option, one for each directory you want to ignore. That is, you cannot separate them by comma, even though that is how it will be displayed when you have more than one being ignored (I think it treats the comma as part of the name, so then neither of the dirs you want to ignore would be ignored):

For instance, if I want to ignore both “lost+found” and “test”, then you must add the following to the config file:

ignore-db-dir=lost+found
ignore-db-dir=test

Then restart mysqld:

mysql> show global variables like 'ignore_db_dirs';
+----------------+-----------------+
| Variable_name  | Value           |
+----------------+-----------------+
| ignore_db_dirs | lost+found,test |
+----------------+-----------------+

Hope this helps.

 

One thought on “Ignoring the lost+found Directory in your Datadir”

  1. Hello,

    You can call mysql_change_db lost+found, even you specified ignore_db_dirs.
    Maybe you have to escape lost+found as mysql50 style.

    Followings are my environment.

    mysql> SELECT @@version;
    +——————–+
    | @@version |
    +——————–+
    | 5.5.40-MariaDB-log |
    +——————–+
    1 row in set (0.00 sec)

    mysql> SELECT @@ignore_db_dirs;
    +——————+
    | @@ignore_db_dirs |
    +——————+
    | lost+found,.ssh |
    +——————+
    1 row in set (0.00 sec)

    mysql> use lost+found
    ERROR 1049 (42000): Unknown database ‘lost+found’

    mysql> use #mysql50#lost+found
    Database changed

    mysql> show tables;
    Empty set (0.00 sec)

    mysql> create table t1 (num int);
    Query OK, 0 rows affected (0.05 sec)

    $ ll data/lost+found/
    合計 108
    -rw-rw—- 1 mysql mysql 8558 10月 20 13:05 2014 t1.frm
    -rw-rw—- 1 mysql mysql 98304 10月 20 13:06 2014 t1.ibd

Comments are closed.