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.
Follow the below steps to execute SQL queries on the MySQL server using phpMyAdmin:
- Make sure you are on the home page.
- Click on the “SQL” tab (at the top of the phpMyAdmin interface).
- Write or Paste SQL query to the SQL editor.
- 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:
- Log in to phpMyAdmin:
Obviously the first thing you need to do is login to your phpMyAdmin.
- Select the Database:
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.
- Go the SQL Tab:
At the top of the phpMyAdmin interface, there should be a menu with tabs such as “Structure,” “SQL,” etc.
Click on the “SQL” tab to open the SQL query editor.
- Write or Paste Your SQL Query:
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
postand 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;
- Execute the Query:
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.
- View the Results:
Once the query has been executed, you will see the results.