Ubuntu – Can’t log into MySQL

MySQL

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.

Best Answer

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;
Related Question