How to Connect to Mysql Server Using VS Code and Fix errors

Last Updated : 11 Aug, 2026

MySQL is a popular relational database management system (RDBMS) used to store, manage, and retrieve data using SQL.

  • Supports CRUD operations.
  • Follows a client-server architecture.
  • Supports languages like Python, Java, and PHP.
  • Uses SQL queries to interact with databases.

Steps to Connect to MySQL Server using VSCode

Step 1: Open Visual Studio Code and install the MySQL Management Tool extension from Extensions.

Step 2: In VS Code, select Add Connection and enter the MySQL server hostname. For a local MySQL installation, enter:

localhost
 

Step 3: If VS Code displays ER_NOT_SUPPORTED_AUTH_MODE, open the MySQL installation folder and navigate to the bin folder to resolve the authentication issue.

 

Step 4: Select the bin folder's file path and type cmd to open the Command Prompt.

 

Step 5: Go to the folder where MySQL is installed and open the bin folder. Select the file path and type cmd to open the Command Prompt.

 

Step 6: In the Command Prompt, enter the following command and provide the MySQL root password:

mysql -u root -p

Step 7: Open the MySQL Command Prompt and create a new user, grant the required privileges, and apply the changes using the following commands:

CREATE USER 'sqluser'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

GRANT ALL PRIVILEGES ON *.* TO 'sqluser'@'%';

FLUSH PRIVILEGES;
 

Step 8: Delete the previous connection.

 

 Step 9: After establishing the MySQL connection, expand the localhost connection in the Explorer panel to view the available databases.

 

Step 10: Type the following commands to create a new database, create a users table, and insert records into it.

CREATE DATABASE myrestaurant;

CREATE TABLE IF NOT EXISTS myrestaurant.users(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(200) NOT NULL,
phone VARCHAR(200),
address VARCHAR(200),
password VARCHAR(200) NOT NULL
);

INSERT INTO myrestaurant.users(name, phone, address, password)
VALUES
('Gaurav', '123456789', 'Mumbai, India', 'pass134'),
('Sakshi', '987654321', 'Chennai, India', 'pass456');

 Step 11: Run the following query to retrieve the records from the users table:

SELECT * FROM `myrestaurant`.`users` LIMIT 1000;

The query displays the inserted records in the Results section.


Comment