MySQL USE and SHOW DATABASES

A MySQL server can hold many databases. Before you work with tables, you must tell MySQL which database to use.


SHOW DATABASES

SHOW DATABASES;
Result (your list can be different)
Database
information_schema
mysql
performance_schema
school
sys

The databases information_schema, mysql, performance_schema and sys belong to MySQL itself. Do not change them.


USE: select a database

USE school;
MySQL says

Database changed


Which database am I using?

SELECT DATABASE();
Result
DATABASE()
school


Use the database name in a query

You can also write the database name before a table name, without the USE command.

SELECT * FROM school.students;
Note: In a program (like PHP or Python), you give the database name when you connect, so USE is not needed. See Python MySQL Connect.

Summary

  • SHOW DATABASES; lists the databases.
  • USE name; selects one, and SELECT DATABASE(); shows the current one.
  • Next: DROP DATABASE.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.