25th Anniversary Savings | 25% Off Dedicated Servers*Shop Now
25th Anniversary Savings | 25% Off VPS Hosting* †††Shop Now
Limited Inventory: High-Performance AMD-Powered Servers Now Available.* Shop Now >
Dedicated Hosting Deals | From $99/moShop Now
Earn hosting credits and a chance to win an Amazon gift card when you refer friends to Liquid Web!Read our promo rules

View the Selected MySQL Database on Linux via Command Line

Reading Time: < 1 minute

Pre-Flight Check

  • These instructions are intended for viewing the selected MySQL database via the command line.
  • I’ll be working from a Liquid Web Core Managed CentOS 7 server, and I’ll be logged in as root.

Login to MySQL

First we’ll login to the MySQL server from the command line with the following command:

mysql -u root -p

In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current root password to complete the login.

If you need to change your root (or any other) password in the database, then follow this tutorial on changing a password for MySQL via the command line.

You should now be at a MySQL prompt that looks very similar to:

mysql>

or

MariaDB [(none)]>

View Selected Database in MySQL

If you haven’t already created any databases, then check out our tutorial: Create a MySQL Database on Linux via Command Line

By default all MySQL operations run via the MySQL command line are performed on the currently selected database; thus, it’s important to know which database is currently selected. To find out issue the following command:

SELECT database();

Your result may be similar to this:

mysql> SELECT database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

Here the result is null, meaning a database is not currently selected. To select a database, follow our tutorial: Select a MySQL Database on Linux via Command Line!

About the Author: J. Mays

As a previous contributor, JMays shares his insight with our Knowledge Base center. In our Knowledge Base, you'll be able to find how-to articles on Ubuntu, CentOS, Fedora and much more!

Latest Articles

How to Edit the PHP Memory for Your WordPress Site via WP Toolkit

Read Article

What is CGI-Bin and What Does it Do?

Read Article

Top 10 Password Security Standards

Read Article

Top 10 Password Security Standards

Read Article

How to Use the WP Toolkit to Secure and Update WordPress

Read Article