[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

I Can't Access MySQL Anymore - Please Help

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
2 Solutions

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>

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/host_name.pid`

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.
piratepatrolAuthor Commented:
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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now