Select a MySQL Database on Linux via Command Line
Pre-Flight Check
- These instructions are intended for selecting a MySQL database on Linux via the command line.
- I’ll be working from a Liquid Web Core Managed CentOS 6.5 server, and I'll be logged in as root.
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 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 this:
mysql>
View Selected Database in MySQL
When executing commands via the MySQL command line, a database may be explicitly specified. However, by default all MySQL operations run via the command line are performed on the currently selected database. 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)
The result is null, meaning a database is not currently selected.
Select a Database in MySQL
To select a database for use with subsequent MySQL operations, use the following command:
USE tutorial_database;
That command should yield a result of Database changed similar to:
mysql> USE tutorial_database;
Database changed
To verify the database has been selected simply issue the following command (which we ran previously):
mysql> SELECT database();
+-------------------+
| database() |
+-------------------+
| tutorial_database |
+-------------------+
1 row in set (0.00 sec)
Related Articles:
About the Author: Justin Palmer
Justin Palmer is a professional application developer with Liquid Web
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Clone a Drupal Site to Another Domain
Read ArticleTop Eight Virtualization Security Issues and Risks
Read ArticleAccessing Man Pages on Ubuntu 16.04 LTS
Read ArticlePremium Business Email Pricing FAQ
Read ArticleMicrosoft Exchange Server Security Update
Read Article