MySQL Connector/J 6.0 Developer Guide

Pre-General Availability Draft: 2018-06-26

6.2 Connection URL Syntax

This section explains the syntax of the URLs for connecting to MySQL.

This is the generic format of the connection URL:


The URL consists of the following parts:


Any reserved characters for URLs (for example, /, :, @, (, ), [, ], &, #, =, ?, and space) that appear in any part of the connection URL must be percent encoded.


There are four possible protocols for a connection:


Depending on the situation, the hosts part may consist simply of a host name, or it can be a complex structure consisting of various elements like multiple host names, port numbers, host-specific properties, and user credentials.


The default database or catalog to open. If the database is not specified, the connection is made with no default database. In this case, either call the setCatalog() method on the Connection instance, or specify table names using the database name (that is, SELECT dbname.tablename.colname FROM dbname.tablename...) in your SQL statements. Opening a connection without specifying the database to use is, in general, only useful when building tools that work with multiple databases, such as GUI database managers.


Always use the Connection.setCatalog() method to specify the desired database in JDBC applications, rather than the USE database statement.


A succession of global properties applying to all hosts, written as key=value and separated by the symbol &. Here are some examples:


The following are true for the key-value pairs: