You are Here: FAQ ->Scripting and Programming Languages->MySQL Database->Article #11


How can I connect to a MySQL5 database on a Dedicated Website Server?


To be able to connect to the database, you will need the following information from the MySQL Administration section from the 1&1 Control Panel:

arrow image Database Name
arrow image Host Name
arrow image User Name
arrow image Password




Below you will find general examples of how to connect to your databases using various programming and scripting languages. You will need to replace the Database Name with your Database Name and your password etc. You must remember to specify the socket /tmp/mysql5.sock which remains the same for all Dedicated Website Servers.


SSH/BASH

mysql -h localhost -u dbo111111111 -p -S /tmp/mysql5.sock db111111111   



PHP

<?php

$hostname="localhost:/tmp/mysql5.sock";
$username="dbo111111111";
$password="myPassword";

$link = mysql_connect("$hostname", "$username", "$password");
if (!$link) {
die('Connection failed: ' . mysql_error());
}
echo 'Connection successful';
mysql_close($link);

?>   



PERL

#!/usr/bin/perl

use DBI;

print "Content-type:text/html\n\n";

$hostname= "localhost";
$username= "dbo111111111";
$password= "MyPassword";
$mysqlsocket= "/tmp/mysql5.sock";

$db_handle = DBI->connect("dbi:mysql:database=mysql;host=$hostname;mysql_socket=$mysqlsocket;user=$username;password=$password")
or die "Connection failed: $DBI::errstr\n";

print "Connection successful";

$db_handle->disconnect();   


Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not useful at all):
1 2 3 4 5