Select Category
Sitemap Help Contact
print article

Connect to a MySQL5 Database on a 1&1 Managed Server

For 1&1 Managed Server packages.

Follow the steps below to connect to a MySQL5 Database on your 1&1 Managed 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:

  • Database Name
  • Host Name
  • User Name
  • 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 Managed 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);

?>
Please note:
Alternatively you can try $hostname = "localhost;unix_socket=/tmp/mysql5.sock"; if you are having trouble connecting using the hostname value supplied above.

Perl

#!/usr/bin_us/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();

For additional information, you may want to reference: