How can you view a database in MySQL?
You can use the following commands to view MySQL database:
- Open the MySQL client:
mysql -u [username] -p
The [username] here is your MySQL username, once you run this command, the system will prompt you to enter your password.
- View all databases.
SHOW DATABASES;
This will display a list of all databases.
- Select a database.
USE [database_name];
The [database_name] here is the name of the database you want to view.
- View the tables in the database.
SHOW TABLES;
This will display all the tables in the selected database.
- View the structure of the table:
DESCRIBE [table_name];
The [table_name] here is the name of the table whose structure you want to view.
- View the data in the table.
SELECT * FROM [table_name];
The [table_name] here is the name of the table where you can view the data.
Note: The above commands need to be executed in the MySQL client.