Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 3306
      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


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

It seems MySQL is not running properly.

share|improve this question
reza, did any of the proposed solutions work for you? If not, which problems remain? – tohuwawohu Apr 11 '12 at 9:12

2 Answers 2

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!

share|improve this answer
This looked very promising, but it did not work for Ubuntu 13.10 Server. The same ERROR 1045 was encountered during mysql -u root mysql. – user207039 Dec 30 '13 at 3:56

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> 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*       LISTEN      1306/mysqld

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

share|improve this answer
tohuwawohu - this is the best answer I've seen. With it, I was able to log into the database. Unfortunately, when the command is executed, it displays "Query OK, 0 Rows Affected, Rows Matched: 4, Rows Changed: 0, Warnings: 0". – user207039 Dec 30 '13 at 4:35
@noloader: Did you encounter the very same issue as described in the question? Did you try to modify the root password as described? If your issue isn't exactly the same as described in the question, you should better open a new question. – tohuwawohu Dec 30 '13 at 9:36
@noloader: 0 Rows Affected is the usual result if the new and the old password are identical - in this case, mysql doesn't modify the password entry at all. – tohuwawohu Dec 30 '13 at 10:05
Thanks tohuwawohu. "... mysql doesn't modify the password entry" - that's good to know. – user207039 Dec 30 '13 at 15:55
tohuwawohu: "Did you encounter the very same issue as described in the question" - yes, I originally had the same problem (even after running dkpg re-configure). tohuwawohu: "Did you try to modify the root password as described" - yes. But there's some other goodness present here (namely, I was trying to finalize an ownCoud installation through its web interface; and ownCloud needed to connect through localhost, and not the FQDN, even though they are the same machine). – user207039 Dec 30 '13 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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