how will you view all the existing databases on the mysql server?
Answers
Answer:
The most common way to get a list of the MySQL databases is by using the mysql client to connect to the MySQL server and run the SHOW DATABASES command. If you haven't set a password for your MySQL user you can omit the -p switch.
Answer:
When administering MySQL database servers, one of the most common tasks you’ll have to do is to get familiar with the environment. This involves tasks such as listing databases that reside on the server, displaying the tables of a particular database or getting information about user accounts and their privileges.
This tutorial explains how to show all databases in a MySQL or MariaDB server through the command line.
Show MySQL Databases
The most common way to get a list of the MySQL databases is by using the mysql client to connect to the MySQL server and run the SHOW DATABASES command.
Access the MySQL server using the following command and enter your MySQL user password when prompted:
mysql -u user -p
If you haven’t set a password for your MySQL user you can omit the -p switch.
From within the MySQL shell execute the following command:
SHOW DATABASES;
The command will print a list of all the databases for which the user have some kind of a privilege granted to. The output will be similar to this:
+--------------------+
| Database |
+--------------------+
| information_schema |
| opencart |
+--------------------+
2 rows in set (0.00 sec)
Another command that you can use to list the databases is SHOW SCHEMAS which is a synonym for the SHOW DATABASES command:
SHOW SCHEMAS;
The output will be the same as when using the SHOW DATABASES command:
+--------------------+
| Database |
+--------------------+
| information_schema |
| opencart |
+--------------------+
2 rows in set (0.00 sec)
Show All MySQL Databases
To list all the databases on the MySQL server you’ll need to login as a user that can access all databases, by default that is the MySQL root user or set a global SHOW DATABASES privilege.
Log in a MySQL root user:
mysql -u user -p
Run the SHOW DATABASES command:
SHOW DATABASES;