Show Me
Let's
take a moment to admire our work and see what we've
done so far. To get a list of databases, use the SHOW
DATABASES statement like so:
SHOW DATABASES; +-----------+ | Database | +-----------+ | bookstore | | mysql | | test | +-----------+
The result of the SHOW
DATABASES statement lists not only the database
that we've created, but also two others. One is the
mysql database, which contains data on user
privileges. This was covered in Chapter 2. The
third one listed is the test database, which is
set up by default when MySQL is installed. It's
there as a convenience for you to be able to add tables or run SQL
statements for testing.
To
see a list of tables in the bookstore database,
once we select the bookstore database with the
USE statement shown earlier, we would enter the
following statement:
SHOW TABLES; +---------------------+ | Tables_in_bookstore | +---------------------+ | authors | | books | +---------------------+
The result of the
SHOWTABLES statement provides
a list containing our two tables, just as we expected. If you want to
see a list of tables from another database while still using the
bookstore database, add a
FROM clause to the previous statement:
USE bookstore; SHOW TABLES FROM mysql;
This displays a list of tables from the mysql database while still anchoring the client in the bookstore database.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access