Chapter 5 MySQL Connections

Table of Contents

5.1 Creating A New MySQL Connection (Simple)
5.2 Creating A New MySQL Connection (Tutorial)
5.3 Manage Server Connections
5.3.1 Standard TCP/IP Connection Method
5.3.2 Local Socket/Pipe Connection Method
5.3.3 Standard TCP/IP over SSH Connection Method
5.3.4 SSL Wizard (Certificates)
5.3.5 System Profile
5.3.6 Configure Server Management Wizard
5.3.7 The Password Storage Vault
5.4 MySQL Fabric Integration
5.5 Client Connections

Manage and create MySQL connections.

5.1 Creating A New MySQL Connection (Simple)

To add a connection, click the [+] icon to the right of the MySQL Connections title on the Home screen. This opens the Setup New Connection form:

Figure 5.1 Setup New Connection Form

Setup New Connection Form

Important

The Configure Server Management button (bottom left) opens an optional configuration wizard for setting shell commands on the host. For example, commands to start/stop the MySQL instance, or to edit configuration file. For more information, see Section 5.3.6, “Configure Server Management Wizard”.

Fill out the connection details and optionally click Configure Server Management to execute the Server Management wizard. Click OK to save the connection.

Important

When opening connections, MySQL Workbench automatically sets the client character set to utf8. Manually changing the client character set, such as using SET NAMES ..., may cause MySQL Workbench to not correctly display the characters. For additional information about client character sets, see Connection Character Sets and Collations.

New MySQL connections are added to the Home screen as a tile, and the Section 8.2.1, “Object Browser and Editor Navigator” describes several MySQL Workbench features to monitor and configure each connected MySQL server. A single MySQL Workbench instance can open one or multiple MySQL connections into individual tabs.

For a more detailed overview of this process, see the tutorial titled Section 5.2, “Creating A New MySQL Connection (Tutorial)”.

5.2 Creating A New MySQL Connection (Tutorial)

  1. Launch MySQL Workbench. You will be presented with the Home window.

    Figure 5.2 Getting Started Tutorial - Home Window

    Getting Started Tutorial - Home Window

  2. Our example already has two connections created, but let us create a new connection. From the MySQL Workbench Home window, click the [+] icon near the MySQL Connections label. This opens the Setup New Connection wizard.

  3. Define the Connection Name value, which we will set to "MyFirstConnection" in this example.

    Figure 5.3 Getting Started Tutorial - Setup New Connection: MyFirstConnection

    Getting Started Tutorial - Setup New Connection: MyFirstConnection

    The default connection values are for a typical local setup, so check them and enter the appropriate values. If you are unsure, click the Test Connection button to check the connection parameters. Do not press OK.

    Next, optionally click Configure Server Management..., which opens up the Configure Local Management wizard:

  4. Read the Configure Local Management introduction, and press Next to begin defining the new connection parameters.

    Figure 5.4 Getting Started Tutorial - Configure Local Management Introduction

    Getting Started Tutorial - Configure Local Management Introduction

  5. The connection will now be tested. You should see that the connection was successful. If not, click Back and check that you have entered the information correctly.

    Figure 5.5 Getting Started Tutorial - Test Database Connection

    Getting Started Tutorial - Test Database Connection

    Toggle the Show Logs to view additional details about the tested connection, then click Next.

  6. Optionally, you may configure a method for remote management if a Remote Host was specified. Setting these options enables MySQL Workbench to determine the location of configuration files, and the correct start and stop commands to use for the connection.

    SSH login based management and Native Windows remote management types are available. The Operating System and MySQL Installation Type are configured for the SSH login variant.

    We are creating a local MySQL connection in this tutorial, so are skipping the Management and OS and SSH Configuration options, as they are used for configuring a remote MySQL connection.

  7. On Microsoft Windows, select the appropriate MySQL service for the MySQL connection.

    Figure 5.6 Getting Started Tutorial - Windows Management

    Getting Started Tutorial - Windows Management

  8. The wizard will now check its ability to access the start and stop commands, and check access to the MySQL Server configuration file.

    Figure 5.7 Getting Started Tutorial - Test Settings

    Getting Started Tutorial - Test Settings

  9. You now have a chance to review the configuration settings. The information displayed varies slightly depending on platform, connection method, and installation type.

    At the Review Settings prompt, choose "I'd like to review the settings again" to review the settings. Choosing "Continue" closes the "Configure Server Management" dialog.

    Figure 5.8 Getting Started Tutorial - Review Settings

    Getting Started Tutorial - Review Settings

    Check the Change Parameters if you want to check or edit information about the MySQL configuration file. In our example we will check it, and click Next to continue.

  10. Review the MySQL configuration file information. Click the Check buttons to perform the described checks, or optionally change the configuration file path.

    Figure 5.9 Getting Started Tutorial - MySQL Config File

    Getting Started Tutorial - MySQL Config File

  11. Optionally, enter your own commands for starting, stopping, and checking the MySQL connection. Typically the default values are used, which means leaving these optional values blank.

    Figure 5.10 Getting Started Tutorial - Specify Commands

    Getting Started Tutorial - Specify Commands

    Click Finish to close the "Configure Server Management" dialog, which reveals the original Setup New Connection window.

  12. After reviewing the Setup New Connection information, press Test Connection again to make sure it still functions, and then OK to create the new MySQL connection.

    Figure 5.11 Getting Started Tutorial - Setup New Connection

    Getting Started Tutorial - Setup New Connection

  13. Your new MyFirstConnection MySQL connection is now listed on the Home window.

    Figure 5.12 Getting Started Tutorial - Home Window Instance

    Getting Started Tutorial - Home Window Instance

  14. From the Home window, click the new MySQL connection to open the SQL editor for this connection. The SQL editor is the default page, so now select the Server Status from the left Navigator panel to display the connected MySQL server's current status.

    Figure 5.13 Getting Started Tutorial - Server Status

    Getting Started Tutorial - Server Status

  15. Test the other Navigator panel options that relate to your new MySQL connection. Check its status, MySQL logs, and measure its performance statistics from the Dashboard.

    Notice the Management and Schemas tabs on the bottom of the Navigator panel. The Schemas view displays the schemas that are associated with your new MySQL connection. Alternatively, you can merge the Schemas and Management tabs by either clicking the merge icon on the top right of the Navigator panel, or by enabling the Show Management Tools and Schema Tree in a single tab SQL Editor preference.

This concludes the "Creating a MySQL connection" tutorial. For additional information about MySQL connections, see Chapter 5, MySQL Connections.

5.3 Manage Server Connections

The Manage Server Connections dialog is another way to manage MySQL connections. This dialog is invoked by either selecting Edit Connection or selecting Database, Manage Connections from the main menu. It can also be invoked from any of the wizards requiring access to a live database.

After the MySQL connection manager is launched, you are presented with the following dialog, with the Connection tab open:

Figure 5.14 Manage Server Connections: Connection Tab

Manage Server Connections: Connection Tab

  • Connection Name: The name used to refer to this connection. This connection can then be selected from a list in other wizards requiring a connection.

  • Connection Method: Method used to connect to the RDBMS.

    After you select a connection method, the fields available in the Parameters, SSL, and Advanced tabs change accordingly. More details about these options and parameters are available below.

Note

The Test Connection button will test the selected MySQL connection and report its connection status. It also reports whether or not SSL is enabled.

For testing remote connections, you might also use ping to check the hostname, or telnet to also check the port. If these fail, then also check the firewall settings on each host, and also that MySQL server is running on the remote host.

Note

Simultaneous client connections: Opening a MySQL connection from the MySQL Workbench home page opens a new connection tab in MySQL Workbench for that connection. Each of these tabs requires two MySQL connections to perform basic tasks, such schema discovery and SQL execution. Additionally, performing management related tasks, such as Server Status, requires two additional MySQL connections. Essentially, this means that each MySQL connection tab in MySQL Workbench requires four available connections to MySQL. For additional information about "Too many connection" related errors, see Too many connections.

This connection requirement doubles with each connection tab opened in MySQL Workbench, even if the two connection tabs point to the same MySQL server. SQL editor tabs share their connections, so having multiple SQL editor and SQL results tabs does not affect the number of required connections.

5.3.1 Standard TCP/IP Connection Method

This connection method enables MySQL Workbench to connect to MySQL Server using TCP/IP.

Note

The --skip-networking MySQL server configuration option affects the TCP/IP connection method. If disabled, use named pipes or shared memory (on Windows) or Unix socket files (on Unix).

Parameters tab

  • Hostname: The host name or IP address of the MySQL server.

    Note

    The host name "localhost" might resolve to "127.0.0.1" or "::1" on your host, so note this when checking permissions. For example, if a web application's user only has access to "127.0.0.1" on a host, and a defined connection uses "localhost" that resolves to "::1", this connection may lack the proper permissions to the aforementioned web application. Ping "localhost" on each host to determine where it resolves to.

  • Port: The TCP/IP port on which the MySQL server is listening (the default is 3306).

  • Username: User name to use for the connection.

  • Password: Optional password for the account used. If you enter no password here, you will be prompted to enter the password when MySQL Workbench attempts to establish the connection. MySQL Workbench can store the password in a vault (see Section 5.3.7, “The Password Storage Vault”).

  • Default Schema: When the connection to the server is established, this is the schema that will be used by default. It becomes the default schema for use in other parts of MySQL Workbench.

Advanced tab

Advanced parameters are less common and include:

Figure 5.15 Standard (TCP/IP) Connection: Advanced Tab

Standard (TCP/IP) Connection: Advanced Tab

The Advanced tab includes these check boxes:

  • Use compression protocol: If checked, the communication between the application and the MySQL server will be compressed, which may increase transfer rates. This corresponds to starting a MySQL command-line client with the --compress option. This option is unchecked by default.

  • Use ANSI quotes to quote identifiers: Treat " as an identifier quote character (like the ` quote character) and not as a string quote character. You can still use ` to quote identifiers with this mode enabled. With this option enabled, you cannot use double quotation marks to quote literal strings, because it is interpreted as an identifier. Note: If this option is checked, it overrides the server setting. This option is unchecked by default.

  • Enable Cleartext Authentication Plugin: Send the user password in cleartext. Required for some authentication methods. This option is unchecked by default.

  • Use the old authentication protocol: This option disables Connector/C++'s secure_auth option. This option unchecked by default.

It also includes these options:

SQL_MODE: Override the default SQL_MODE used by the server.

Others: Other options for Connector/C++ as option=value pairs, one per line.

SSL tab

SSL parameters include:

  • Use SSL: This dropdown provides options related to enabling SSL encryption. Choose No to disable SSL, If available if the client library supports it, or Require to require SSL support for the MySQL connection to succeed. This option defaults to If available.

  • SSL CA File: Path to the Certification Authority file for SSL.

  • SSL CERT File: Path the Certificate file for SSL.

  • SSL Key File: Path to the Key file for SSL.

  • SSL Cipher: Optional list of permissible ciphers to use for SSL encryption.

  • SSL Wizard: Generate SSL certificates for both the MySQL server and MySQL client. Requires access to OpenSSL binaries in the system's PATH. For additional information, see Section 5.3.4, “SSL Wizard (Certificates)”.

  • Files: Opens a system's file browser that points to the generated SSL files by the SSL Wizard.

5.3.2 Local Socket/Pipe Connection Method

This connection method enables MySQL Workbench to connect to MySQL Server using a socket file (on Unix) or a named pipe (on Windows).

Parameters

The unique field here is Socket/Pipe Path. Enter the name of the socket or pipe here. If the field is left blank, the default socket or pipe name is used. On Unix, the default socket name is /tmp/mysql.sock. On Microsoft Windows, the default pipe name is MySQL.

Figure 5.16 Manage DB Connections - Socket/Pipe Parameters

Manage DB Connections - Socket/Pipe Parameters

Advanced

These are the same options discussed in Section 5.3.1, “Standard TCP/IP Connection Method”, except there is not the Use compression protocol option.

SSL

These are the same options discussed in Section 5.3.1, “Standard TCP/IP Connection Method”.

5.3.3 Standard TCP/IP over SSH Connection Method

This connection method enables MySQL Workbench to connect to MySQL Server using TCP/IP over an SSH connection.

Parameters

In addition to a number of parameters that are in common with Standard TCP/IP connections, this connection method features a number of specialized parameters. These are listed here:

  • SSH Hostname: This is the name of the SSH server. An optional port number can also be provided. For example, localhost:22.

  • SSH Username: This is the name of the SSH user name to connect with.

  • SSH Password: The SSH password. It is recommended that an SSH key file is also used.

  • SSH Key File: A path to the SSH key file.

If a remote host is missing from the system's list of known hosts, a prompt requires you to confirm the host's fingerprint before storing it. If your stored host fingerprint is different than the host's current fingerprint, then an error is generated and you will be required to handle the discrepancy from outside of MySQL Workbench before creating the connection. Prior to MySQL Workbench 6.1.6, the host SSH fingerprint was not saved by MySQL Workbench.

On Linux and OS X, SSH host fingerprints are stored in ~/.ssh/known_hosts. On Microsoft Windows, they are stored in a file created by MySQL Workbench under the user's application data folder (%appdata%), such as C:\Users\[username]\AppData\Roaming\MySQL\Workbench\known_hosts.

The SSH connection options are viewable in the following screenshot:

Figure 5.17 Manage DB Connections - SSH Parameters

Manage DB Connections - SSH Parameters

Advanced

The options here are the same as for the Standard TCP/IP connection. See Section 5.3.1, “Standard TCP/IP Connection Method”.

SSL

The options here are the same as for the Standard TCP/IP connection. See Section 5.3.1, “Standard TCP/IP Connection Method”.

5.3.4 SSL Wizard (Certificates)

This wizard helps create SSL certificates for both MySQL clients and MySQL servers. Connections in MySQL Workbench are updated with the certificates by the wizard. This wizard requires OpenSSL to create the certificates. An example my.cnf / my.ini file is also generated that utilizes the generated certificates.

Note

The OpenSSL binary should be in the system's PATH.

Figure 5.18 SSL Wizard: Welcome

SSL Wizard: Welcome

Figure 5.19 SSL Wizard: Options

SSL Wizard: Options

Figure 5.20 SSL Wizard: Results

SSL Wizard: Results

5.3.5 System Profile

The System Profile tab enables you to specify host-specific information. This is achieved primarily through selecting a System Type, along with its corresponding Installation Type. These profile settings contain standard information that is used in managing the host's MySQL instance.

Here are some of the available installation types:

  • FreeBSD, MySQL package or Custom

  • Linux, including distributions such as Fedora, Oracle, RHEL, SLES, Ubuntu, Generic, and Custom

  • OS X, MySQL package or Custom

  • OpenSolaris, MySQL package or Custom

  • Windows, with different installation methods, MySQL versions, and build architectures

Choose the appropriate System Type and Installation Type to set default parameters that includes commands used to start and stop MySQL, commands to check the server status, the location of the my.ini or my.cnf configuration file, and on Windows, the Windows Service Name. These default values are customizable.

Figure 5.21 Manage Server Connections: System Profile Tab

Manage Server Connections: System Profile Tab

The Remote Management tab is available when connecting to MySQL remotely.

Figure 5.22 Manage Server Connections: Remote Management Tab

Manage Server Connections: Remote Management Tab

5.3.6 Configure Server Management Wizard

Clicking the [+] icon from the Home page launches the Setup New Connection wizard. The wizard provides a MySQL connection form to create a new MySQL connection, and includes a Configure Server Management option as a step-by-step approach to creating a new MySQL server connection. This can also be executed later (on remote connections) when from the home page by clicking the top right corner of a MySQL connection tile:

Figure 5.23 Configure Remote Management

Configure Remote Management

Executing this wizard is required to perform tasks requiring shell access to the host. For example, starting/stopping the MySQL instance and editing the configuration file.

The steps presented in the wizard are as follows:

  1. Test DB Connection

  2. Management and OS

  3. SSH Configuration

  4. Windows Management

  5. Test Settings

  6. Review Settings

  7. MySQL Config File

  8. Specify Commands

Test DB Connection

On this page, MySQL Workbench tests your database connection and displays the results. If an error occurs, click Show Logs to view the related logs.

Management and OS

Used to specify a remote management type and target operating system, which is available when the Host Machine is defined as a remote host.

The SSH login based management option includes configuration entries for the Operating System and MySQL Installation Type.

SSH Configuration

If you specified a Remote Host on the Specify Host Machine page, you will be presented with the Host SSH Connection page, that enables you to use SSH for the connection to the server instance. This facility enables you to create a secure connection to remotely administer and configure the server instance. You must enter the host name and user name of the account that will be used to log in to the server for administration and configuration activities. If you do not enter the optional SSH Key for use with the server, then you will be prompted for the password when the connection is established by MySQL Workbench.

Note

This connection is to enable remote administration and configuration of the MySQL Server itself. It is not the same as the connection used to connect to a server for general database manipulation.

Note

You must use an SSH connection type when managing a remote server if you wish to start or stop the server or edit its configuration file. Other administrative functions do not require an SSH connection.

Windows Management

If a Windows server is used, then setting the Windows configuration parameters is mandatory. Windows management requires a user account with the required privileges to query the system status, and to control services. And read/write access to the configuration file is needed to allow editing of the file.

Test Settings

The wizard now attempts a connection to your server and reports the results. If an error occurs, click Show Logs to view the related logs.

MySQL Workbench must know where the MySQL Server configuration file is located to be able to display configuration information. The wizard is able to determine the most likely location of the configuration file, based on the selection made on the Operating System page of the wizard. However, it is possible to test that this information is correct by clicking the Check path and Check section buttons. The wizard then reports whether the configuration file and server configuration section can in fact be accessed. It is also possible to manually enter the location of the configuration file, and the section pertaining to MySQL Server data; these manually entered values should be tested using the buttons provided. Click the Next button to continue.

Review Settings

The modified settings may be reviewed, which also includes the default values. Check the Change Parameters checkbox if the MySQL Config File section will be edited, and then click Next to continue.

MySQL Config File

Allows configuration of the MySQL server version. It also allows the editing and validation of the configuration file path, and validation of the server instance section. Click Next to continue.

Specify Commands

Optionally set the commands required to start, stop, and check the status of the running MySQL server instance. Commands can be customized, if required, but the defaults are suitable in most cases. The defaults depend on the selected options on the Operating System page of the wizard. Click Next to continue.

Complete Setup

Name the MySQL server instance on the final step. This name is used throughout MySQL Workbench as a reference to this MySQL connection. After setting a suitable name, click Finish to save the instance.

5.3.7 The Password Storage Vault

The vault provides a convenient secure storage for passwords used to access MySQL servers. By using the vault, you need not enter credentials every time MySQL Workbench attempts to connect to a server.

Note

The hostname is used for storing password information. For example, a local connection might use "localhost", "127.0.0.1", or "::1", but these are stored separately in the password storage vault, even if they all resolve to the same place.

The vault is implemented differently on each platform:

  • Windows: The vault is an encrypted file in the MySQL Workbench data directory. This is where connections.xml and related files are located. The file is encrypted using a Windows API which performs the encryption based on the current user, so only the current user can decrypt it. As a result it is not possible to decrypt the file on any other computer. It is possible to delete the file, in which case all stored passwords are lost, but MySQL Workbench will otherwise perform as expected. You then must re-enter passwords as required.

  • OS X: The vault is implemented using the OS X Secure Keychain. The keychain contents is also viewable from the native Keychain Access.app utility.

  • Linux: The vault works by storing passwords using the gnome-keyring daemon, which must be running for password persistence to work. The daemon is automatically started in GNOME desktops, but normally is not in KDE and others. The gnome-keyring daemon stores passwords for MySQL Workbench on non-GNOME platforms, but it must be started manually.

5.4 MySQL Fabric Integration

Browse, view status, and connect to any MySQL instance in a Fabric Cluster.

Note

This requires Connector/Python and MySQL Fabric 1.5 and above installed, including the Python module. This feature also requires MySQL Workbench 6.3+.

Fabric 1.5 support was added in MySQL Workbench 6.3, and due to incompatible protocol changes, Fabric 1.4 support was dropped. Also, MySQL Workbench 6.2 added Fabric 1.4 support.

To set up a managed Fabric connection, create a new MySQL connection with the new MySQL Fabric Management Node connection method. The connection tiles have a different look:

Figure 5.24 Fabric Connection Group Tile

Fabric Connection Group Tile

Clicking the new fabric group tile shows the managed connections:

Figure 5.25 Fabric Connection Group Tiles

Fabric Connection Group Tiles

5.5 Client Connections

The client connection browser lists the active and sleeping MySQL client connections, and adds the ability to kill statements and connections, and view additional connection details and attributes.

Note

The connection details viewer requires MySQL 5.6 or greater. Only basic connection information is available for previous versions of MySQL, such as the connection hosts, database, and state.

Figure 5.26 Client Connection Overview

Client Connection Overview

Client Connections and Metadata locks

The Client Connections management window includes a Show Details for connections to MySQL 5.6 and above. These details are separated into three tabs:

  • Details: connection details such as Process ID, Type, User, Host, Instrumented, and additional information.

    Figure 5.27 Client Connections Details

    Client Connection Details

  • Locks: MySQL uses metadata locking to manage access to objects such as tables and triggers. Sometimes a query might be blocked while being manipulated by another connection from another user. The Locks feature utilizes these MySQL metadata locks (MDL) to show the locked connections that are blocked or being waiting on, and shows information about the locks, what they are waiting for, and what they hold.

    Figure 5.28 Metadata Locks Browser

    Metadata Locks Browser

    Note

    The metadata lock information is provided in the performance schema as of MySQL server 5.7.3.

  • Attributes: these are connection attributes such as OS, Client Name, Client Version, and Platform.

    Figure 5.29 Client Connection Attributes

    Client Connection Attributes