MYSQL CONNECTION STRINGS

www.

How do I use a connection string to connect to a MySQL database?

The following article explains how to use a connection string to connect to a MySQL database from a Windows server. The syntax of the connection string will vary based on the programming language you are using. Below are sample connection strings for ColdFusion, Perl and ASP. The code snippets can be added directly to your code.

In the following examples, please substitute your information where the following data is referenced:

  • server: enter the MySQL server that you are assigned to, for example, mysql4.safesecureweb.com
  • username: enter the username provided for your database
  • password: enter the password provided for your database
  • database: enter the database name provided for your database
  • DSN: enter the DSN name (ColdFusion only)

ColdFusion

<CFQUERY Name="test" DATASOURCE="DSN" USERNAME="username"
PASSWORD="password">
</CFQUERY>

Perl

#!/usr/bin/perl

use DBI;

$db = DBI-connect("dbi:mysql:database:servername","username","password")
or die("Couldn’t connect");

$db-disconnect;

ASP

<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=server; PORT=3306; DATABASE=database; USER=username; PASSWORD=password; OPTION=3;"

%>

Comments are closed.

By using this website you consent to the use of cookies in accordance with our Privacy Notice. You may opt-out at any time in the Cookies section of the Privacy Notice page.