To run an SQL query in phpMyAdmin, open the database, click the SQL tab, type your query and click Go. This guide shows you how. It uses a generic example database, so replace the names in the examples with your own.

Before you start

SQL (Structured Query Language) is the language used to read and change data in a database. Some queries permanently change or delete data, so back up your database first.

  • You need to be logged in to phpMyAdmin (a web tool for managing databases).
  • You need the name of the database and, if relevant, the table you want to query.

Find your database details in your welcome email or in the client area at https://my.hostking.host.

How to run an SQL query

cPanel

  1. Log in to cPanel.
  2. In the Databases section, click phpMyAdmin.
  3. In the left pane, click the name of your database.
  4. Click the SQL tab.
  5. Type or paste your query in the box.
  6. Click Go.

DirectAdmin

  1. Log in to DirectAdmin.
  2. Click MySQL Management.
  3. Click phpMyAdmin next to your database. You are logged in automatically.
  4. In the left pane, click the name of your database.
  5. Click the SQL tab.
  6. Type or paste your query in the box.
  7. Click Go.

What the query applies to

The query applies to whatever is selected in the left pane. If you select a database, the query applies to that database. If you select a table, it applies only to that table.

You can run several statements together by separating them with a semicolon (;).

Example: changing a table structure

This example removes a column from a table. Replace the placeholder names with your own table and column names:

ALTER TABLE your_table DROP COLUMN your_column;

Click Go, then click OK when phpMyAdmin asks you to confirm. A message confirms that the query ran.

Troubleshooting

  • Syntax error: phpMyAdmin highlights the error in the SQL box. Read the message on the results page and correct the highlighted part.
  • Access denied: The SQL tab cannot manage databases or database users. Use the database and user tools in your control panel for those tasks.
  • phpMyAdmin will not open (DirectAdmin): Check that the database and a database user exist in MySQL Management.
  • Need help with SQL syntax: See the MySQL documentation for the statement you are using. For help with your hosting account, contact support through live chat or a support ticket in the client area.
Was this answer helpful? 0 Users Found This Useful (3 Votes)