Login into phpmyadmin without username and password

By | June 25, 2013

Phpmyadmin auto login

Phpmyadmin is a popular web based mysql database administration tool/frontend. It is used widely by php/mysql developers to manage database locally and remotely. When logging in to phpmyadmin, the user has to provide the mysql login credentials.

However when working or developing on localhost , its better to make phpmyadmin login automatically without asking for username and password everytime. On localhost security is not much of an issue and developers are busy developing and its important to save time.

To enable passwordless login to phpmyadmin, we have to edit the php configuration file named config.inc.php
So first navigate to the directory where phpmyadmin is installed. If you installed phpmyadmin manually then it should be in the apache web root directory (/var/www on ubuntu from example).

Edit config.inc.php

To do this the config.inc.php file needs to be edited as follows :

1. Look for the configuration line for 'auth_type'. It is by default set to cookie. Set it to 'config'. This means that the authentication should be done from configuration data instead of login cookie.

$cfg['Servers'][$i]['auth_type'] = 'config';

2. Next, add the mysql username and password to the config file

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['username'] = 'root';
$cfg['Servers'][$i]['password'] = 'your_password';

3. Save the configuration file , clear browser cache and then reopen phpmyadmin in your browser. Make sure you clear the browser cache , otherwise the login page may still come back.

If the 'config.inc.php' file is not found then look for 'config.sample.inc.php'. Make a copy of it and name it as 'config.inc.php' , then edit the file.

Ubuntu

If you installed phpmyadmin from synaptic on ubuntu then editing the config.inc.php file might not work as expected. This is because the configuration file setup in this case is a bit tricky. I checked it on ubuntu 12.10

Phpmyadmin files are installed to the following locations on ubuntu

/usr/share/phpmyadmin/
/etc/phpmyadmin/

The first directory will have all the phpmyadmin application files. Whereas the second directory will the configuration file config.inc.php. It is this file that needs to be edit.
So edit the following file

/etc/phpmyadmin/config.inc.php

You will notice that the configuration directives are inside an php if clause

if (!empty($dbname)) {
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'config';
.........

Do not edit over there. Instead scroll down to the bottom and add the following 3 lines

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['username'] = 'root';
$cfg['Servers'][$i]['password'] = 'secret';

Save the file and then open phpmyadmin in your browser. It should login right away without asking for password.

This different location for configuration file is defined in the "libraries/vendor_config.php" file in the phpmyadmin installation directory. Which in this case is "/usr/share/phpmyadmin/libraries/vendor_config.php". It contains the following lines which define the actual location of the config.inc.php file to be used.

/**
 * Directory where configuration files are stored.
 * It is not used directly in code, just a convenient
 * define used further in this file.
 */
define('CONFIG_DIR', '/etc/phpmyadmin/');

/**
 * Filename of a configuration file.
 */
define('CONFIG_FILE', CONFIG_DIR . 'config.inc.php');

Resources

http://wiki.phpmyadmin.net/pma/auth_types
About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

4 Comments

Login into phpmyadmin without username and password
  1. mowglisanu

    I had no config.inc.php in my phpmyadmin directory so I renamed config.sample.inc.php to config.inc.php then added
    $cfg[‘Servers’][$i][‘auth_type’] = ‘config’;
    $cfg[‘Servers’][$i][‘username’] = ‘root’;
    $cfg[‘Servers’][$i][‘password’] = ‘your_password’;
    and it worked perfectly

  2. Zaf

    hi, i got the error while tried up those configuration,

    then i change

    $cfg[‘Servers’][$i][‘username’] = ‘root’;

    to

    $cfg[‘Servers’][$i][‘user’] = ‘root’;

    and it worked out :D

Leave a Reply

Your email address will not be published. Required fields are marked *