MySQL Command Line Client

Last Updated -


Need to initiate a command line MySQL connection? We've got your covered! In this article, we'll show you how to do it either by using WP-CLI or directly using the mysql command.

Using WP-CLI

WP-CLI is installed on all VPS/Enterprise hosting accounts and is a great tool to simplify WordPress-related actions, including connecting to your database.

For more information, take a look at our guide on connecting to your database with WP-CLI.

Without WP-CLI

If you'd prefer not to use WP-CLI to initiate my MySQL connection, you can always do so manually using the mysql command.

Note: Due to security procedures, you won't be able to connect directly to your MySQL database from a remote location. If you need initialize a MySQL connection, you'll need to either do so from an SSH session on the server or through an SSH tunnel.

Getting Your Connection Details

To get your MySQL connection details such as your username, password, and database host, perform the following:

  1. Connect to your site via SSH.
  2. Next, run the following command, replacing example.com with your site's primary domain:
    cat ~/sites/example.com/wp-config-hosting.php | grep define
  3. After running the previous command, you'll be shown several definitions that exist inside the wp-config-hosting.php file. The information that you'll need is the following:

    • DB_NAME: Your database name.
    • DB_USER: The username associated with your database.
    • DB_PASSWORD: Your database user's password.
    • DB_HOST: The host that your database is located at.

Connecting To Your MySQL Database

Once you have all of your database connection details, use the following command to connect to your MySQL database:

mysql -u DB_USER -p DB_PASSWORD -h DB_HOST DB_PASSWORD

After initializing the connection, you should now see a MySQL command prompt.

Related Topics

Pagely is the Managed WordPress Hosting Platform designed to exceed the needs of media, business, and Enterprise customers alike. We help the world's biggest brands scale WordPress.

Copyright © 2006-2017 Pagely, Inc. All rights reserved.
Pagely® and WordPress® are registered trademarks.

Pagely
Powered by Zendesk