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
Write a query to get all column names of a database table
Write a query to create a new table with the data and structure of another table
Interview Questions & Answers
Write a query to create a new table which consists of data and structure copied from the other table
What is a primary key in MySQL?
What is a foreign key in MySQL?
What is the difference between CHAR and VARCHAR in MySQL?
What is normalization in MySQL?
What is AUTO_INCREMENT in MySQL?
What is the difference between primary key and unique key?