In this article, we’ll be quickly exploring MySQL. The DBMS doesn’t contain any user databases as you’ll shortly observe. Follow the steps below for this exercise:
Hope you gone through the pervious post
This Articles Contents
Basic commands which we quickly exploring MySQL
-- The articles queries are reproduced below for convenient copy/paste into the my sql terminal
-- Query 1
SHOW DATABASES;
-- Query 2
USE mysql;
-- Query 3
SHOW CREATE DATABASE mysql;
-- Query 4
SHOW TABLES;
-- Query 5
DESCRIBE user;
-- Query 6
SHOW CREATE TABLE servers;
-- Query 7
SHOW COLUMNS FROM servers;
SHOW DATABASES
Format
SHOW DATABASES;
You’ll see four databases that are used by the system. The query only shows databases that you have the privilege to view.
USE database
In order to explore a particular database, we need to tell the DBMS that we want our queries directed to the database of our choice. For our case, let’s pick the existing MySQL database by executing the following command:
USE mysql;
The MySQL prompt will respond with a “Database changed” message. The USE statements allow us to let MySQL know the database we want to interact with. Any queries we execute in the future are directed to the selected database.
SHOW CREATE DATABASE dbName;
The database MySQL has been created for us already. We can examine how the database was created using the following query:
SHOW CREATE DATABASE mysql;
The line /*!40100 DEFAULT CHARACTER SET latin1 */ is a comment and encloses MySQL extensions to the SQL standard. For instance, the numeral 40100 indicates the minimum version of MySQL that can process the SHOW CREATE DATABASE query.
SHOW TABLES
Let’s explore the MySQL database further. We’d like to know what tables the MySQL database holds. We can do this by using the SHOW statement as follows:
SHOW TABLES;
The response is a long list of tables, the mysql database holds
DESCRIBE user
We can also explore the structure of a table using the DESCRIBE command. Let’s describe the user table as follows:
DESCRIBE user;
The output will show the various columns the table is made of, the data type of each column, and other related metadata.
SHOW CREATE TABLE
We can also use the SHOW statement to display how the table was created. For instance, the following query shows how the servers table was created:
SHOW CREATE TABLE servers;
SHOW COLUMNS FROM table
We can display the column information for a table using the SHOW statement. For example:
SHOW COLUMNS FROM servers;
This completes a brief exploratory tour of mysql and the various commands we can use to explore it.