run SQL queries using phpMyAdmin

How to Run SQL Queries in phpMyAdmin?

Using phpMyAdmin you can run SQL queries in two places – 1. On the MySQL Server, 2. On a Specific Database.

Run SQL query/queries on the MySQL server using phpMyAdmin:

In the MySQL server, we execute –

  • MySQL server-related queries like – Server status, View Server Variables, Shutdown, Restart, etc.
  • Database-related queries like – Create/Delete databases, show databases, etc.
  • Users-related queries like – Create/Delete a user.
  • Privileges-related queries.
  • etc.

Follow the below steps to execute SQL queries on the MySQL server using phpMyAdmin:

Run SQL Queries on MySQL server using phpMyAdmin
  1. Make sure you are on the home page.
  2. Click on the “SQL” tab (at the top of the phpMyAdmin interface).
  3. Write or Paste SQL query to the SQL editor.
  4. Click on the “Go” button to execute the query.

Run SQL query/queries on a Specific Database using phpMyAdmin:

We typically execute queries related to tables on a database because a MySQL Table resides within a database.

To run SQL queries on a database in phpMyAdmin, follow these steps:

  1. Log in to phpMyAdmin:

    Obviously the first thing you need to do is login to your phpMyAdmin.

  2. Select the Database:
    Step 1 - select a MySQL database in phpMyAdmin

    After logging in, you’ll see the phpMyAdmin interface. On the left-hand side, you’ll see a list of databases.

    Click on the database where you want to run your SQL query. This will make that database the active one.

  3. Go the SQL Tab:

    At the top of the phpMyAdmin interface, there should be a menu with tabs such as “Structure,” “SQL,” etc.

    Step 2 - Click on the SQL Tab to write SQL Queries in phpMyAdmin

    Click on the “SQL” tab to open the SQL query editor.

  4. Write or Paste Your SQL Query:
    Step 3 - Write or paste SQL Query to the SQL editor in phpMyAdmin

    In the SQL query editor, you can write or paste your SQL query. Ensure that your query is syntactically correct.

    The following example query creates a table called post and its structure inside the selected database.

    CREATE TABLE `posts` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `title` varchar(100) NOT NULL,
      `content` text NOT NULL,
      `author` varchar(30) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
  5. Execute the Query:
    Step 4 - Click on the Go button to execute the query in phpMyAdmin

    After writing or pasting your SQL query, you can execute it by clicking the “Go” button, which is usually located at the bottom right or bottom left of the SQL query editor.

  6. View the Results:
    Step 5 - See the result.

    Once the query has been executed, you will see the results.