accessing phpmyadmin db from terminal now in ubuntu 13.04 i firstly installed mysql server with sudo apt-get install mysql-server mysql server version 5.5 now in terminal i can check if it is working by

sudo netstat -tap | grep mysql

it responds me by prompting me for password and then

tcp        0      0 localhost:mysql         *:*                     LISTEN             26214/mysqld

but to connect using my root account i typed mysql -u root -p prompting for password it shows ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES)

when i try this /opt/lampp/bin/mysql -u root -p it ask for password and says ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2)

what is there in /etc/mysql/my.cnf and what is in /opt/lampp/bin/mysql

any solution?

6 Answers 6


Have you tried setting up password for root soon after installing MySQL?? If not first try to Enter the command in a terminal below;

mysql -u root

Now it should open the mysql console. And type the following line:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

To exit from the mysql console enter exit.

Then try reconnecting with following line;

mysql -u root -p

Try the password you've entered.

Source: How to connect and create a database in MySQL?

  • but when i again try to connect by mysql -u root -p its showing `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    – black
    Jan 21, 2014 at 15:26
  • this error came after try the above steps??
    – AzkerM
    Jan 21, 2014 at 17:26
  • yes. could not open phpmyadmin from localhost xampp.
    – black
    Jan 21, 2014 at 21:34
  • @AzkerM I got the same error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' Oct 22, 2016 at 3:58
  • @KasunSiyambalapitiya - Would you please elaborate this with a new question referencing this post or any other steps you have tried.. and with few more information. A single comment will not help to track down the cause. :)
    – AzkerM
    Oct 22, 2016 at 5:47

Use the following command

/opt/lampp/bin/mysql -u root -p

Then Enter after that it requires enter password if you have changed the password of root than type this password otherwise simply press Enter keeping it blank.

  • This solves the above error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock Oct 22, 2016 at 4:00

yes man.after i followed those steps i was able to connect to phpmyadmin from terminal but after a restart i see i cant access phpmyadmin from localhost

#2002 - No such file or directory The server is not responding (or the local server's socket is not correctly configured) and also status from localhost shwing mysql database deactivated . all other like SSI,PHP,CGI is activated. in security section its howing phpmyadmin as unknown and mysql user root no password unknown.

before it was all activated and secured i have done that to set password for root and localhost with all preveiledged when i installed xampp in linux. my config.inc.php file.location /opt/lampp/phpmyadmin

$cfg['blowfish_secret'] = '$5hfhjfhgst5fg4%43(*&'; /* YOU SHOULD CHANGE THIS FOR A     MORE SECURE COOKIE AUTH! */

/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'wtf11111';
/* 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'] = true;

In my.cnf located in /etc/mysql/my.cnf

port        = 3306
socket      = /var/run/mysqld/mysqld.sock

[mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0

[mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking


You can reset the password for the MySQL by login to the safe mode.

Stop the MySQL service by using the below command.

/etc/init.d/mysql stop

Then start the MySQL using in the safe mode

mysqld_safe --skip-grant-tables

Once login to the MySQL using the safe mode, please execute the below command to update the password.

UPDATE user SET Password=password('MySQL_PWD') WHERE User='root'; FLUSH PRIVILEGES;


After executing the above command kill the mysqld and start the MySQL.

Now try login to the MySQL with the updated password.



/opt/lampp/bin/mysql -u root

and then use

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

to set your password and then use ctrl + c or use exit to logout from mysql then use

/opt/lampp/bin/mysql -u root -p

and type password (password is hidden ) and ENTER then enjoy


Your installation is correct. Make sure you enter the password in the root account and not in your local account. To switch to root account, in the terminal type "sudo -i" and now you'll get the root user privileges. Now enter "mysql -u root -p" and the password , it will surely work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.