Documentation Home
MySQL and Windows
Related Documentation Download this Excerpt

MySQL and Windows  /  ...  /  Code Editors

6.5.2 Code Editors

This section explains how to make use of the code editors in MySQL for Visual Studio.

Introduction

MySQL for Visual Studio provides access to MySQL objects and data without forcing developers to leave Visual Studio. Designed and developed as a Visual Studio package, MySQL for Visual Studio integrates directly into Server Explorer providing a seamless experience for setting up new connections and working with database objects.

The following MySQL for Visual Studio features are available as of version 2.0.2:

  • JavaScript and Python code editors, where scripts in those languages can be executed to query data from a MySQL database.

  • Better integration with the Server Explorer to open MySQL, JavaScript, and Python editors directly from a connected MySQL instance.

  • A newer user interface for displaying query results, where different views are presented from result sets returned by a MySQL server like:

    • Multiple tabs for each result set returned by an executed query.

    • Results view, where the information can be seen in grid, tree, or text representation for JSON results.

    • Field types view, where information about the columns of a result set is shown, such as names, data types, character sets, and more.

    • Query statistics view, displaying information about the executed query such as execution times, processed rows, index and temporary tables usage, and more.

    • Execution plan view, displaying an explanation of the query execution done internally by the MySQL server.

Getting Started

The minimum requirements are:

  • MySQL for Visual Studio 2.0.5

  • Visual Studio 2012

  • MySQL 5.7.12 with X Plugin enabled (Code editors are not supported for use with MySQL 8.0 servers.)

To enable X Plugin for MySQL 5.7:

  1. Open a command prompt and navigate to the folder with your MySQL binaries.

  2. Invoke the mysql command-line client:

    mysql -u user -p
  3. Execute the following statement:

    mysql> INSTALL PLUGIN mysqlx SONAME 'mysqlx.dll';
    Important

    The mysql.session user must exist before you can load X Plugin. mysql.session was added in MySQL 5.7.19. If your data dictionary was initialized using an earlier version you must run the mysql_upgrade procedure. If the upgrade is not run, X Plugin fails to start with the following error message:

    There was an error when trying to access the server with user: mysql.session@localhost. Make sure the user is present in the server and that mysql_upgrade was ran after a server update.

Opening a Code Editor

Before opening a code editor that can run scripts against a MySQL server, a connection needs to be established:

  1. Open the Server Explorer pane by clicking View.

  2. Right-click the Data Connections node and select Add Connection.

  3. In the Add Connection window, make sure the MySQL Data Provider is being used and fill in all the information.

    Note

    To enter the port number, click Advanced and set the Port among the list of connection properties.

  4. Click Test Connection to ensure you have a valid connection, then click OK. The new connection with its tables, views, stored procedures, and functions now appears within the Data Connections list of Server Explorer.

  5. Right-click the connection, select New MySQL Script, and then select the language of the editor (JavaScript or Python) to open a new MySQL script tab in Visual Studio.

To create a new editor for existing MySQL connections, you need only to do the last step.

Using the Code Editor

An open editor includes a toolbar with the actions that can be executed. The first two buttons in the toolbar represent a way to connect or disconnect from a MySQL server. If the editor was opened from the Server Explorer, the connection will be already established for the new script tab.

The third button is the Run button, the script contained in the editor window is executed by clicking it and results from the script execution are displayed in the lower area of the script tab.