1and1 Help Centre Categories

print article

Connect to a MySQL Database Using PHP and Perl

For 1&1 WebHosting. For 1&1 Managed Servers, connect to a MySQL5 database.

To connect to a MySQL database, you will need the complete MySQL Database login information from the MySQL Administration section of the 1&1 Control Panel.
This will include the following:

  • Database Name
  • Host Name
  • User Name
  • Password

Below you will find examples of how to connect to your databases using SSH, PHP and Perl. When executing the script, replace the example database name and password with your information.


mysql -h db1111.oneandone.co.uk -u dbo111111111 -p db111111111

After pressing ENTER, you will be prompted for the database password.




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

$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
    die ('Can\'t select database: ' . mysql_error());
else {
    echo 'Database ' . $database . ' successfully selected!';





use DBI;

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

$hostname= "db1111.oneandone.co.uk";
$username= "dbo111111111";
$password= "myPassword";

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

print "Connection successful";


For additional information, you may want to reference: