Knowledgebase

Connecting to MySQL from the Command Line Print

  • developersgitdeployment, developers, database, phpmyadmin, cpanel, backup, password, troubleshooting
  • 0

Direct database access over SSH.

CONNECTING

Use the mysql client with your database username and the -p flag to prompt for the password. The host is localhost.

Remember the cPanel prefix: database and user names both carry your cPanel username followed by an underscore.

USEFUL COMMANDS ONCE CONNECTED

Show databases you can access Select a database to work in Show tables Describe a table's structure Run queries

Exit with quit.

WHY USE IT

Faster than phpMyAdmin for a quick query Works when phpMyAdmin times out on a large table Scriptable, which phpMyAdmin is not Necessary for large imports and exports

CAUTION

There is no undo. A DELETE or UPDATE without a WHERE clause affects every row.

Run a SELECT with the same WHERE clause first and check the row count before running the destructive version.

Take a backup before anything substantial.

FOR EXPLORATION

phpMyAdmin is more comfortable for browsing. The command line is better for anything repeated or large.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot