Oc_mounts table dropped

Nextcloud version (eg, 20.0.5): 27.0.2
Operating system and version (eg, Ubuntu 20.04): docker container

The issue you are facing:
Nextcloud doesnt find files because I removed the oc_mounts table

Is this the first time you’ve seen this error? Y(Y/N)_:

Steps to replicate it:

  1. Delete the oc_mounts table

I just need the mysql command to create the table, then I use db:add-missing-indicies to rebuild the db!

Congrats!
I hope for you that you have a backup of your database.

Unfortunately I have to disappoint you, it doesn’t work that way. The oc_mounts table is one of the central database tables without which it is impossible to determine how everything is connected to the file system.
The command occ db:add-missing-indicies won’t do anything, it’s intended for completely different tasks.

In short: either database dump (backup) or new installation

But since you are obviously quite adventurous and probably want to try it yourself, here is some information about the relevant table (from one of my virtual machines):

MariaDB [nextcloud]> SHOW COLUMNS FROM oc_mounts;
+----------------------+---------------+------+-----+---------+----------------+
| Field                | Type          | Null | Key | Default | Extra          |
+----------------------+---------------+------+-----+---------+----------------+
| id                   | bigint(20)    | NO   | PRI | NULL    | auto_increment |
| storage_id           | bigint(20)    | NO   | MUL | NULL    |                |
| root_id              | bigint(20)    | NO   | MUL | NULL    |                |
| user_id              | varchar(64)   | NO   | MUL | NULL    |                |
| mount_point          | varchar(4000) | NO   |     | NULL    |                |
| mount_id             | bigint(20)    | YES  | MUL | NULL    |                |
| mount_provider_class | varchar(128)  | YES  | MUL | NULL    |                |
+----------------------+---------------+------+-----+---------+----------------+
7 rows in set (0,001 sec)

MariaDB [nextcloud]> SHOW INDEX FROM oc_mounts;
+-----------+------------+-----------------------------+--------------+----------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table     | Non_unique | Key_name                    | Seq_in_index | Column_name          | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Ignored |
+-----------+------------+-----------------------------+--------------+----------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| oc_mounts |          0 | PRIMARY                     |            1 | id                   | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_storage_index        |            1 | storage_id           | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_root_index           |            1 | root_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_mount_id_index       |            1 | mount_id             | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_class_index          |            1 | mount_provider_class | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| oc_mounts |          1 | mount_user_storage          |            1 | storage_id           | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mount_user_storage          |            2 | user_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_user_root_path_index |            1 | user_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_user_root_path_index |            2 | root_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| oc_mounts |          1 | mounts_user_root_path_index |            3 | mount_point          | A         |           0 |      128 | NULL   |      | BTREE      |         |               | NO      |
+-----------+------------+-----------------------------+--------------+----------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
10 rows in set (0,000 sec)

So in order to create a table with exactly the same properties, you have to use the following SQL statement:

CREATE TABLE oc_mounts (
    id bigint(20) NOT NULL AUTO_INCREMENT,
    storage_id bigint(20) NOT NULL,
    root_id bigint(20) NOT NULL,
    user_id varchar(64) NOT NULL,
    mount_point varchar(4000) NOT NULL,
    mount_id bigint(20),
    mount_provider_class varchar(128),
    PRIMARY KEY (id),
    KEY mounts_storage_index (storage_id),
    KEY mounts_root_index (root_id),
    KEY mount_user_storage (storage_id, user_id),
    KEY mounts_mount_id_index (mount_id),
    KEY mounts_class_index (mount_provider_class),
    KEY mounts_user_root_path_index (user_id, root_id, mount_point(128))
);

Here the result, creating a table “new_oc_mounts”:

MariaDB [nextcloud]> CREATE TABLE new_oc_mounts (
    ->     id bigint(20) NOT NULL AUTO_INCREMENT,
    ->     storage_id bigint(20) NOT NULL,
    ->     root_id bigint(20) NOT NULL,
    ->     user_id varchar(64) NOT NULL,
    ->     mount_point varchar(4000) NOT NULL,
    ->     mount_id bigint(20),
    ->     mount_provider_class varchar(128),
    ->     PRIMARY KEY (id),
    ->     KEY mounts_storage_index (storage_id),
    ->     KEY mounts_root_index (root_id),
    ->     KEY mount_user_storage (storage_id, user_id),
    ->     KEY mounts_mount_id_index (mount_id),
    ->     KEY mounts_class_index (mount_provider_class),
    ->     KEY mounts_user_root_path_index (user_id, root_id, mount_point(128))
    -> );
Query OK, 0 rows affected (0,141 sec)

MariaDB [nextcloud]> SHOW COLUMNS FROM new_oc_mounts;
+----------------------+---------------+------+-----+---------+----------------+
| Field                | Type          | Null | Key | Default | Extra          |
+----------------------+---------------+------+-----+---------+----------------+
| id                   | bigint(20)    | NO   | PRI | NULL    | auto_increment |
| storage_id           | bigint(20)    | NO   | MUL | NULL    |                |
| root_id              | bigint(20)    | NO   | MUL | NULL    |                |
| user_id              | varchar(64)   | NO   | MUL | NULL    |                |
| mount_point          | varchar(4000) | NO   |     | NULL    |                |
| mount_id             | bigint(20)    | YES  | MUL | NULL    |                |
| mount_provider_class | varchar(128)  | YES  | MUL | NULL    |                |
+----------------------+---------------+------+-----+---------+----------------+
7 rows in set (0,001 sec)

MariaDB [nextcloud]> SHOW INDEX FROM new_oc_mounts;
+---------------+------------+-----------------------------+--------------+----------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| Table         | Non_unique | Key_name                    | Seq_in_index | Column_name          | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Ignored |
+---------------+------------+-----------------------------+--------------+----------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
| new_oc_mounts |          0 | PRIMARY                     |            1 | id                   | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_storage_index        |            1 | storage_id           | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_root_index           |            1 | root_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mount_user_storage          |            1 | storage_id           | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mount_user_storage          |            2 | user_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_mount_id_index       |            1 | mount_id             | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_class_index          |            1 | mount_provider_class | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_user_root_path_index |            1 | user_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_user_root_path_index |            2 | root_id              | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
| new_oc_mounts |          1 | mounts_user_root_path_index |            3 | mount_point          | A         |           0 |      128 | NULL   |      | BTREE      |         |               | NO      |
+---------------+------------+-----------------------------+--------------+----------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
10 rows in set (0,001 sec)

As you can easily see, I created a table with the statement with exactly the same properties.
Now it only has to be populated with the correct data. THAT is only possible with a backup.

much luck!

Thank you so much. I dropped my makeshift oc_mounts table and created one with you CMD; Then I did:
php occ maintenance:repair
and nextcloud rebuilt the table, now I have my files back!!!

THANKS

1 Like

WOW!

I truely didn’t expect that works!

Congratulations. :+1:

By the way, this is how the Table is created if you have made a database dump with mysqldump:

CREATE TABLE `oc_mounts` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `storage_id` bigint(20) NOT NULL,
  `root_id` bigint(20) NOT NULL,
  `user_id` varchar(64) COLLATE utf8mb4_bin NOT NULL,
  `mount_point` varchar(4000) COLLATE utf8mb4_bin NOT NULL,
  `mount_id` bigint(20) DEFAULT NULL,
  `mount_provider_class` varchar(128) COLLATE utf8mb4_bin DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `mounts_storage_index` (`storage_id`),
  KEY `mounts_root_index` (`root_id`),
  KEY `mounts_mount_id_index` (`mount_id`),
  KEY `mount_user_storage` (`storage_id`,`user_id`),
  KEY `mounts_class_index` (`mount_provider_class`),
  KEY `mounts_user_root_path_index` (`user_id`,`root_id`,`mount_point`(128))
) ENGINE=InnoDB AUTO_INCREMENT=2818 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

Much luck!