I Can't Access MySQL Anymore - Please Help

Posted on 2004-11-15
Last Modified: 2010-04-20
Hi friends,

I fooled around with the user table in the mysql database.  I ran the following command just for kicks:

update user set password='boo';

After I restarting my computer, I can no longer access mysql.  The error message is

ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)

FYI, before I fooled around with the user table, I was able to connect to MySQL via PHP with the username "root" and no password.

Please kindly help me resolve this issue.  I don't know where to start.  I'm a Linux newbie.  You folks are so awesome.

Jazon from Jacksonville, FL
Question by:piratepatrol
    LVL 38

    Assisted Solution


    1. # mysql -u root -h localhost -p"
    and do not give any password press enter.
    2. edit /etc/my.cnf
    3. # mysqladmin -u root password <new password>
    for setting password
    4. # mysqladmin -u root -p password <new password>
    enter password: <old password>

    LVL 12

    Accepted Solution

    for resetting the root password is as follows:

    Log on to your system as either the Unix root user or as the same user that the mysqld server runs as.
    Locate the `.pid' file that contains the server's process ID. The exact location and name of this file depend on your distribution, hostname, and configuration. Common locations are `/var/lib/mysql/', `/var/run/mysqld/', and `/usr/local/mysql/data/'. Generally, the filename has the extension of `.pid' and begins with either `mysqld' or your system's hostname. Now you can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the pathname of the `.pid' file in the following command: shell> kill `cat /mysql-data-directory/`

    Note the use of backticks rather than forward quotes with the cat command; these cause the output of cat to be substituted into the kill command.
    Restart the MySQL server with the special --skip-grant-tables option: shell> mysqld_safe --skip-grant-tables &

    Set a new password for the root@localhost MySQL account: shell> mysqladmin -u root flush-privileges password "newpwd"

    Replace ``newpwd'' with the actual root password that you want to use.
    You should now be able to connect using the new password.
    Alternatively, on any platform, you can set the new password using the mysql client:

    Stop mysqld and restart it with the --skip-grant-tables option as described earlier.
    Connect to the mysqld server with this command: shell> mysql -u root

    Issue the following statements in the mysql client: mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd')
        ->                   WHERE User='root';

    Replace ``newpwd'' with the actual root password that you want to use.
    You should now be able to connect using the new password.
    LVL 3

    Author Comment

    Hey guys,

    I just went ahead and formatted the harddrive and installed Fedora 2 again.  Thanks for your help anyway.  I split the point between you guys.

    Thanks a bunch,

    Jazon from Jacksonville, FL

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now