Main Content

MySQL ODBC for Linux

This tutorial shows how to set up a data source and connect to a MySQL® database using the command line. The tutorial uses the MySQL Connector/J 5.1.46 driver to connect to a MySQL Version 5.5.16 database on the Linux® platform.

Step 1. Verify the driver installation.

The ODBC driver is typically preinstalled on your computer. For details about the driver installation or troubleshooting the installation, contact your database administrator or refer to your database documentation on ODBC drivers.

If you need to install an ODBC driver, contact your database administrator or see Installing Connector/ODBC on Unix-Like Systems.

Step 2. Set up the data source.

Follow the instructions in Configuring a Connector/ODBC DSN on Unix to create a data source name (DSN).

Step 3. Connect using the command line.

  1. Connect to the database using the configured DSN, user name username, and password pwd with the odbc function. For example, this code assumes that you are connecting to an ODBC data source MySQL.

    datasource = "MySQL";
    username = "username";
    password = "pwd";
    conn = odbc(datasource,username,password);
  2. Close the database connection.


See Also


Related Topics