6

Even after I reset the root password with the following command I cannot log into MySQL. (Other commands listed to provide additional info.)

    # sudo dpkg-reconfigure mysql-server-5.1

    # mysql -u root -p
    Enter password:
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    # telnet 127.0.0.1 3306
      Trying 127.0.0.1...
      telnet: Unable to connect to remote host: Connection refused
    # ps -Aw |grep mysql
      26522 ?        00:00:00 mysqld

    # /etc/init.d/mysql start
    Rather than invoking init scripts through /etc/init.d, use the service(8)
    utility, e.g. service mysql start

    Since the script you are attempting to invoke has been converted to an
    Upstart job, you may also use the start(8) utility, e.g. start mysql

Also,

     # sudo mysqladmin -u root password 123
     mysqladmin: connect to server at 'localhost' failed

It seems MySQL is not running properly.

TRiG
  • 2,006
Reza
  • 61

5 Answers5

5

This works whenever I need to do this ...

Stop the MySQL Server:

sudo /etc/init.d/mysql stop

Start the mysqld configuration.

sudo mysqld --skip-grant-tables &

Login to MySQL as root.

mysql -u root mysql

Replace YOURNEWPASSWORD with your new password!

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
Rinzwind
  • 309,379
3

There should be another admin user, debian-sys-maint. Check the file /etc/mysql/debian.cnf for its password (it isn't encrypted).

Using this password, log into your mysql server:

mysql -u debian-sys-maint -p

and set a new password for user root:

mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit;

You may check first if mysql is running and listening for connections:

sudo netstat -atpn | grep mysql

It should give you something like

tcp 0  0 127.0.0.1:3306     0.0.0.0:*       LISTEN      1306/mysqld

If mysql doesn't run, you should check /var/log/mysql.err and /var/log/mysql.log for details.

tohuwawohu
  • 7,502
1

You can try as sudo

sudo mysql -uuser -p

I've installed mysql to an ubuntu server and couldn't login anymore. Then I tried with sudo and it worked...

0

Run the following commands:

mysql -uroot -p -hlocalhost
sudo service mysql restart
mysql -u root -p

That should work.

bademba
  • 311
0

I faced similar prob at the end, i was able to log into this way (replace "user" with actual user)

mysql -h 127.0.0.1 -u "user"

This was because i had to specify the host and had not set a password of the "user" account.

Tobi Obadiah
  • 162
  • 1
  • 17