Default

What is the statement to list the MySQL databases?

Q) What is the statement to list the available MySQL databases?

a) LIST DATABASES;

b) SHOW DATABASES;

c) SHOW DATABASES:

d) SHOW DATABASES \G

Choose all the correct options.

Explanation

Let’s understand why some options are incorrect and the then learn the correct options and reasons for them.

Incorrect Options

Options a) and c) are NOT correct.

LIST DATABASES; is not a valid MySQL statement. We get the following error when we issue the statement. Hence option a is NOT correct.

mysql> LIST DATABASES;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIST DATABASES’ at line 1

The valid statement terminator is ; or \G  or \g. Semi-colon is not the correct statement terminator and the mysql prompt doesn’t end with the semi-colon. Hence option c is NOT correct.

Correct Answer

The correct options are  b) and d).

SHOW DATABASES; and SHOW DATABASES \G are valid statements to list the available MySQL databases.

SHOW DATABASES; statement displays the output in tabular format as shown below:

mysql> SHOW DATABASES;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
| worlddemo |
+——————–+
7 rows in set (0.00 sec)

 

LIST DATABASES MySQL

 

SHOW DATABASES \G statement displays the output as row format as shown below:

mysql> SHOW DATABASES \G
*************************** 1. row ***************************
Database: information_schema
*************************** 2. row ***************************
Database: mysql
*************************** 3. row ***************************
Database: performance_schema
*************************** 4. row ***************************
Database: sakila
*************************** 5. row ***************************
Database: sys
*************************** 6. row ***************************
Database: world
*************************** 7. row ***************************
Database: worlddemo
7 rows in set (0.00 sec)

List Available MySQL Databases

Hence, b and d are correct options.

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/