banner



How To Install Mysql Connector In Visual Studio Code

In this article, I'll walk you lot through setting up Visual Studio Code for MySQL and MariaDB development using a third-party VS Code extension and requite an overview of the bones features.

VS Lawmaking has been a very popular code editor because it has support for virtually every popular programming language. For the majority of programming languages, support ships in the box. Even so, some common programming languages are not supported out-of-the-box, only support can be easily added by installing extensions from the VS Code Market.

So, let'southward run across how we can customize Visual Studio Lawmaking to adjust your MySQL and MariaDB evolution and management needs by installing an extension from Marketplace, ApexSQL Database Power Tools for VS Code.

Introduction

Created to meet the demands of developers by the team who'south responsible for providing free killer tools for SQL Server, this recently published VS Code extension enables users to connect to MySQL and MariaDB servers in the code editor, allowing them to run queries, perform object searches, export query results, and more.

Judging by the public roadmap, the extension is on an ambitious release schedule with lots of features coming up soon. With that in mind, let's fire upwards the code editor, install the extension, and see what it can practice.

Connecting to MySQL or MariaDB instances

The extension can be installed either from Marketplace, integrated extension manager inside Visual Studio Code, or using the VSIX installation file available as a download on this page. I'g gonna get with the integrated extension managing director, merely feel free to use whatever of the other 2 methods.

Bring up the Extensions view past clicking on the Extensions icon in the Activity Bar on the left side of code editor or go to View | Extensions from the main menu:

Extensions option from the main menu in Visual Studio Code

Start typing the name of the VS Lawmaking extension, and it should pop-up in the search results. At the moment of writing this article, the official product version is 2022.three.xix. To install the extension, click the Install button shown below:

Database Power Tools for VS Code extension from VS Code Marketplace

Once the installation is complete, you'll see one additional icon in the Activity Bar. Clicking on the icon will bring up ApexSQL server explorer which is used for connecting to MySQL or MariaDB instances using TCP/IP or a local socket or pipe:

ApexSQL server explorer in Visual Studio Code

I've already added a few instances, as can be seen higher up, only permit'south add another ane by clicking on the plus (+) sign on the top right of connexion explorer. This action will open the Connect to server tab in which I'll enter needed data to connect to MySQL Server using TCP/IP over an SSH connection:

Connect to server dialog in Visual Studio Code

Once everything is set up, merely click Connect, and if connection parameters are correct, you'll see a message in the lesser right corner of Visual Studio Code saying "Connection successful". The Connect to server tab closes, and the focus goes to ApexSQL server explorer in which you'll find the newly added instance of MySQL Server:

Highlighted MySQL Server in connection explorer

Executing queries and creating statements

How that we've seen how to add together servers, let's movement on to the adjacent step, and see what nosotros tin can do from here. Connectedness explorer provides a user interface to view and manage the objects in each instance of MySQL and MariaDB servers directly from Visual Studio Lawmaking.

For case, we can delete the sakila database by right-clicking on it and choosing the Bear witness DROP script option. This will open up a new query editor and identify the syntax of the Drib DATABASE statement:

Show DROP script option from the right-click context menu in connection explorer

To complete the operation, click the Execute button (besides available from the right-click context bill of fare) in the top left corner of the query editor. We only deleted all tables in the sakila database and database itself permanently. Just don't worry – this is but a sample database, and nosotros tin can recreate information technology someday. Allow's run into how nosotros tin do that.

Back in ApexSQL server explorer, correct-click our instance and choose New query:

New query option in connection explorer

In the newly opened query editor, I'll just paste the SQL script for creating the sample database and hit the Execute button to recreate the database:

Executed SQL script for creating schemas of Sakila sample database

  • Note: The Sakila sample database is bachelor from this page.

If the connection is remote, give information technology a few seconds. There's always a slight delay when dealing with remote locations. It also depends on the complexity of the script that you're running, the number of batches, etc.

I'll run another long script to populate the tables with sample data:

Executed SQL script for populating Sakila sample database with data

You can ever verify your connection and status of a query in the lower status bar:

The status bar of Visual Studio Code

One time the script is executed successfully, caput over to connection explorer, right-click Databases and select Refresh to get latest changes, and you'll see that the objects are recreated:

Refresh option from the connection explorer

Now that we have some actual information in the sample database, let's see how the results of queries can be viewed in Visual Studio Code straight in a spreadsheet-similar grid.

Fetching data from a tabular array, of form, requires a SELECT argument to be executed. So, open a new query, paste the code from below, and execute information technology:

Query results are displayed right beneath the SQL editor:

Executed SQL script in Visual Studio Code with a Query results pane

Aside from executing queries, the VS Code extension as well enables users to generate DDL and DML scripts using the integrated SQL editor.

To generate DDL and DML scripts, correct-click a supported object from connexion explorer and choose an appropriate option. Clicking either of those options will automatically open a new query editor and generate script, prepare for execution:

DDL and DML options from the right-click context menu in connection explorer for generating scripts

Saving query results

The query results tin can be exported and saved to Excel, CSV, JSON, and HTML file formats. This tin be washed in just a few clicks.

Once you're satisfied with the outcome set, use the export icons in the upper correct corner of the query results to export information:

Query results exporting options

I've exported result gear up from above to Excel and here'due south how it looks when opened:

Query results in an Excel spreadsheet

Exporting results to other supporter file formats works pretty much the aforementioned way.

Searching for objects in databases

The side by side handy database feature is the ability to search for objects (similar cyberspace searches), particularly on databases with thousands of objects. Searching for objects in database object definitions has never been easier using this VS Code extension.

To search for objects in MySQL and MariaDB databases, right-click an example or a database from connectedness explorer and choose the Object search option:

Object search option in connection explorer from VS Code extension

In the newly opened Object search tab, enter a keyword in the Search phrase field and click the Find push to initiate a search. Brand certain that targeted server, as well as database, is selected:

Object search tab in VS Code extension

Search scope can exist customized by choosing types of objects that should be included in the search on the right. You tin can play with those to narrow downwardly a search and find objects faster. Furthermore, y'all can jump to whatsoever constitute object in connectedness explorer by clicking on the bluish hyperlink under the Name column.

  • Note: To larn more well-nigh what the VS Code extension does, encounter ApexSQL Database Ability Tools for VS Code for a commencement-time user

What'south next in VS Lawmaking extension

I'm particularly looking forward to the upcoming formatting feature in this VS Code extension planned for the 2022 R4 version. Information technology will allow users to format MySQL and MariaDB scripts using a predefined profile. ApexSQL has been well known for its SQL formatter tool for SQL Server.

Looking at the roadmap, each new version of the VS Code extension will bring something to the tabular array. Information technology'south nice to see that they are slowly expanding MySQL front by adding features from popular MS SQL tools to this production as well.

This means that a data search is also coming up, and it will allow users to rapidly observe data in MySQL and MariaDB databases. Yet, I'g more excited about the browsable visual hints list while typing AKA IntelliSense. This volition speed coding up by inserting keywords, databases, schemas, objects, parameters, variable names, etc. So, stay tuned, and for more than information, visit the ApexSQL Database Power Tools for VS Code extension production folio.

Conclusion

For database developers who prefer working in Visual Studio Code, an extension that adds database support for MySQL and MariaDB is much needed. ApexSQL Database Power Tools for VS Code allows users to perform simple connexion configuration, writing statements and running queries, searching for database objects, and more to come. In other words, it provides extensive database evolution and management tools in Visual Studio Code.

I promise this article has been informative for you and I thanks for reading information technology.

  • Writer
  • Contempo Posts

Bojan Petrovic

Source: https://www.sqlshack.com/visual-studio-code-for-mysql-and-mariadb-development/

Posted by: fryerricated.blogspot.com

0 Response to "How To Install Mysql Connector In Visual Studio Code"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel