How To Execute SQL Queries In PhpMyAdmin?

Executing SQL code in phpMyAdmin is a common task for managing MySQL databases. In this step-by-step tutorial guide your will learn how to execute or run SQL queries to a database using phpMyAdmin.

1. Access phpMyAdmin:

Open your web browser and enter the URL for phpMyAdmin. This is typically located at http://localhost/phpmyadmin/ if you’re running it locally or provided by your web host.

2. Login to phpMyAdmin if needed:

Enter your MySQL username and password to log in to phpMyAdmin.

3. Select the Database by Clicking on the DB Name:

On the left-hand side of the phpMyAdmin interface, you’ll see a list of databases. Click on the name of the database where you want to execute the SQL code. This will ensure that the SQL queries affect the selected database.

select a database where you want to execute the SQL code

4. Go to SQL Tab at the top of the phpMyAdmin:

At the top of the phpMyAdmin interface, you’ll see a row of tabs. Click on the “SQL” tab to switch to the SQL execution interface.

Go to SQL Tab at the top of the phpMyAdmin

5. Enter SQL Code in the Editor:

In the text area provided, you can enter or paste your SQL code. This can include statements such as CREATE TABLE, INSERT INTO, SELECT, UPDATE, DELETE, and more.

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;

6. Execute SQL Code by Clicking Go Button:

After entering the SQL code, you can execute it by clicking on the “Go” button below the text area. phpMyAdmin will execute the SQL code against the selected database.

Execute SQL Code in phpMyAdmin

7. See the Result of the SQL Code You Executed:

If the SQL code generates any output, such as query results or error messages, it will be displayed below the SQL text area. You can review the results to verify that the SQL code executed as expected.

Result of the SQL Code You Executed

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies to ensure that we give you the best experience on our website. Privacy Policy