I'm having some difficulties with MySQL on my Ubuntu box. Just installed Apache, MySQL, PHP and phpMyAdmin. phpMyAdmin gives:

#1045 Cannot log in to the MySQL server

on every login attempt. I've tried username 'root' and empty password, username 'root' and password 'root', username 'mysql' and password 'mysql', username 'mysql' and password 'root'.

I also get Access denied for user [email protected] error when I try to run mysql in terminal:

mysql -u root


mysql -u root -p


sudo mysql

or any of the combinations listed above. I also get access denied when I try these:

mysqladmin -u root password secret

sudo /etc/init.d/mysql stop


service mysql stop

gives unknown instance.

So - can anyone tell me how to get into my database? Thanks.


When I run ps aux | grep mysql I see sudo mysqld --skip-grant-tables.

Update 2:

After reboot I see mysqld running. Then I try service mysql stop and get the following:

user@host:$ service mysql stop
stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.47" (uid=1000 pid=2267 comm="stop mysql ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))


Update 3:

I finally managed to change my root password by using this command:

sudo dpkg-reconfigure mysql-server-5.1

Still have no idea why I couldn't log in before (don't remember setting any password previously). Also, not sure if the deamon now will run correctly after a reboot...

3 Answers 3


OK, I think the first thing is to check whether it's actually running. Execute

ps aux | grep mysql

and check for a line containing mysqld. If there is one, it's running and you should be able to connect (more below). If there isn't, then your service isn't running and therefore you can' connect to or stop it.

It's also possible it has become a zombie (although I have never seen that). In that cased your easiest choice is probably to restart the entire box. I know this sounds drastic, but zombies are quite hard to kill (hence the name).

If the service is running, but you still can't connect, then maybe MySQL isn't listening.

By default, MySQL will only allow connections from If you are trying to connect through the actual IP address of the computer, you need to tell MySQL to listen on that IP address. The relevant lines is in my.cnf and looks like this:

bind-address            =

Modify the address to the IP address of your network interface and restart the service. Or, alternatively, connect to

  • Yes, looks like mysqld is running.. see updated question
    – o01
    Commented Jul 7, 2011 at 23:30
  • Going to try rebooting like you suggest...
    – o01
    Commented Jul 7, 2011 at 23:32

The hint here is:


Your Upstart service entry has a bug of some kind in it, preventing it from starting/stopping properly. Are you running Lucid? If so, look here for some additional help. Basically, it sounds like a packaging bug.


The password for the "root" account on ubuntu (well, the password you use for sudo since root is disabled by default) is not the same password as the root password for mysql, it was probably provided during the install.

If you dont know the password and want to reset it you can do the following

  1. Stop mysql with service mysql stop or /etc/init.d/mysql stop
  2. Start mysqld_safe skipping grant tables:

    mysqld_safe --skip-grant-tables --skip-networking &

  3. Login, change password (root password will be disabled in this mode)

    root@vps:~# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.41-3ubuntu12.10-log (Ubuntu)

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql> update mysql.user set Password=Password("foobar") where user="root"; Query OK, 3 rows affected (0.02 sec) Rows matched: 3 Changed: 3 Warnings: 0

    mysql> flush privileges; Query OK, 0 rows affected (0.03 sec)

    4; Stop the mysqld_safe process, restart mysql and you should know have your root password. There are plenty of other guides on how to do this on Google,, just google for "reset mysql root password"

  • Yes, as I wrote; I get error on "/etc/init.d/mysql stop" and "service mysql stop"
    – o01
    Commented Jul 7, 2011 at 23:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .