Photo by Christina @ wocintechchat.com on Unsplash
How to Connect MySQL Database from Visual Studio and run SQL Queries using SQL Tools Extension
First Open Visual Studio.
Click on Extensions, and search for sqltools. Then click on the result as displayed below:
Install the extensions SQL Tools and also SQL Tools MySQL/MariaDB/TiDB.
SQL Tools extension:
SQL Tools MySQL/MariaDB/TiDB extension:
After installations, a database icon appears on the left side bar, click on it. Then create a new connection by clicking on Add New Connection.
Select the desired database, in this case MySQL:
Then provide My SQL connection details. Before proceeding to this step ensure to create a Connection and Database on MySQL Workbench. As follows:
Firs open MySQL workbench then click on the +(plus) sign next to MySQL Connections
Then create Set Up a New Connection
Then Log In to the Database Connection:
Create a Database within the MYSQL connection.
Having ensured that the previous steps have been executed in MySQL Workbench, one can now proceed to the Database connection setup on Visual Studio code.
At this point, provide MySQL connection details and test the connection:
Then save the connection.
Running SQL Queries
First activate the Database connection.
One can now write python scripts to perform various SQL actions. Such as below.
Select the database users, then write python script and run on active connection.
Happy Learning!