question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mariadb: showAllTables lists tables from other databases

See original GitHub issue

What are you doing?

With mariadb, showAllTables lists all tables on the server (except system tables), rather than only those tables in the current database (which seems to be the behavior with other dialects, in particular mysql and postgres).

  const sequelize = new Sequelize(config.dbUrl);
  console.log(await sequelize.getQueryInterface().showAllTables());

What do you expect to happen?

[]

What is actually happening?

Tables from other databases on the server.

Notably, this means that dropAllTables will attempt to clear out other databases, too.

The query seems to be using information_schema.tables, but (unlike Postgres) information_schema is global in MySQL/MariaDB. (Switching dialect to mysql, which uses SHOW TABLES, works.)

Dialect: mariadb Dialect version: mariadb@2.0.3 Database version: 10.3 Sequelize version: master Tested with latest release: Yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
sushantdhimancommented, Oct 1, 2019

🎉 This issue has been resolved in version 5.19.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

2reactions
rushercommented, Mar 28, 2019

Sequelize documentation about showAllTables indicate

This method returns the name of all existing tables in the database.

So either documentation must be changed to “all existing tables in the schema”. or current implementation is ok.

I think there is some confusion here :

first compare with MySQL sequelize implementation. MySQL implementation in sequelize has no schema handling (a table ‘TABLE’ with schema ‘SCHEMA’ will result creating a table ‘SCHEMA_TABLE’ in current schema). MariaDB sequelize implementation result creating a SCHEMA.TABLE table. So thing are not really comparable.

When comparing with other DB that support schema in sequelize (mssql and postgresql) Other do :

  • mssql : “SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES” meaning listing all tables in all schemas of current database.
  • postgresql: “SELECT table_name FROM information_schema.tables WHERE table_schema = ‘public’ AND table_type LIKE ‘%TABLE’ AND table_name != ‘spatial_ref_sys’;” listing all tables for ‘public’ schema.

So not sure what to do there.

If to be done, correction would be:

--- lib/dialects/mariadb/query-generator.js	(revision 96f5b0e93fb396ef540afc61c1f626534963695e)
+++ lib/dialects/mariadb/query-generator.js	(date 1553764748334)
@@ -29,7 +29,7 @@
   }
 
   showTablesQuery() {
-    return 'SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA NOT IN (\'MYSQL\', \'INFORMATION_SCHEMA\', \'PERFORMANCE_SCHEMA\') AND TABLE_TYPE = \'BASE TABLE\'';
+    return 'SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = SCHEMA() AND TABLE_TYPE = \'BASE TABLE\'';
   }

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Ways to List All Tables in a MariaDB Database
Below are four ways to list out the tables in a MariaDB database using SQL or the command line. The SHOW TABLES Command....
Read more >
SHOW TABLES - MariaDB Knowledge Base
SHOW TABLES lists the non- TEMPORARY tables, sequences and views in a given database. The LIKE clause, if present on its own, indicates...
Read more >
How do I list the tables in a MySQL database? - Alvin Alexander
To list/show the tables in a MySQL database: Log into your database using the mysql command line client; Issue the use command to...
Read more >
How to show all the tables present in the database and server ...
We may sometimes require to get the list of all the tables present in our database. This can be done by using the...
Read more >
Query to show all tables and their collation - Stack Overflow
Just so you can not select a table, you always need to know from which database it is. Name of the tables is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found