Login Automatically in phpMyAdmin When Accessed from Same Computer

phpMyAdmin is one of the widely used tool while developing database centric application using MySQL. Developers frequently access it while developments are going on, to check the values or manipulate data within database tables. By default, we have to login before accessing the databases. It becomes tedious when we perform login frequently.

In this article I am going to show how to configure your phpMyAdmin instance, to make it usable without login when accessed from same machine. So, you don't need to login manually each time you access phpMyAdmin, same time protecting it from external access through network without login.

It is very easy to configure a phpMyAdmin to use without login. But, here we limit that to users who access it from same machine. Please follow the instructions given below to accomplish it.

First, go to phpMyAdmin's root directory. There you can see a file named 'config.sample.inc.php'. Copy that file and put 'config.inc.php' as file name for that new copy. Now open 'config.inc.php' and put following lines after initial server configurations.

// We can grant access based on configured credentials
// if server address is of localhost.
if ($_SERVER['SERVER_ADDR'] == '127.0.0.1') {
  $cfg['Servers'][$i]['auth_type'] = 'config';

  $cfg['Servers'][$i]['user'] = 'root';
  $cfg['Servers'][$i]['password'] = '<password>';
}

Apply your correct root password for the MySQL server in place of <password>.

Now, overall server configuration lines should look like:

/*
 * Servers configuration
 */
$i = 0;

/*
 * First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

// We can grant access based on configured credentials
// if server address is of localhost.
if ($_SERVER['SERVER_ADDR'] == '127.0.0.1') {
  $cfg['Servers'][$i]['auth_type'] = 'config';

  $cfg['Servers'][$i]['user'] = 'root';
  $cfg['Servers'][$i]['password'] = '<password>';
}

No need to touch any existing lines. Just need to put the new if condition.

Now access your phpMyAdmin without login!