Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Before I screw up something, when login using $ mysql -u root -p, and show databases:

| Database           |
| information_schema |
| mysql              |
| performance_schema |
| game_data          |
| test               |

Then I try to create a new user and notice something is wrong with the PRIVILEGES.

So I deleted the new users, and I guess I removed the 'root' and 'Admin' accidentally.

Then I try to create 'root' again, but get Access denied error when doing grant all privileges.

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

If I login mysql again using $ mysql -u root -p, and show databases,

| Database           |
| information_schema |

All the other databases are gone.

How do I fix mysql now?

I cannot cannot find the database 'mysql', cannot create database, create user, anything I try to do will get an error

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

Should I reinstall mysql using macports? If reinstall, I will lost the database 'game_data', right?

share|improve this question

migrated from Jun 3 '13 at 8:32

This question came from our site for professional and enthusiast programmers.

Try accesing the server with 'root'@'' which is diferent from 'root'@'localhost'. Then issue a command to create the user 'root'@'localhost' and grant all privileges to it. – Gimmy Jun 3 '13 at 8:06
Also see How to have MySQL entitle the root user? on Super User. It attempts to avoid resetting passwords. – jww Apr 2 at 11:28
up vote 69 down vote accepted

Follow the steps below.

  1. Start the MySQL server instance or daemon with the --skip-grant-tables option (security setting).

    $ mysqld --skip-grant-tables
  2. Execute these statements.

    $ mysql -u root mysql
    $mysql> UPDATE user SET Password=PASSWORD('my_password') where USER='root';

If you face the unknown field Password error above use:

update user set authentication_string=password('my_password') where user='root';
  1. Finally, restart the instance/daemon without the --skip-grant-tables option.

    $ /etc/init.d/mysql restart

You should now be able to connect with your new password.

$ mysql -u root -p

Enter password: my_password

Fix for MySQL “Unable to lock ibdata1” error

sudo mv /usr/local/mysql/data/ibdata1 /usr/local/mysql/data/ibdata1.bak
sudo mv /usr/local/mysql/data/ib_logfile0 /usr/local/mysql/data/ib_logfile0.bak
sudo mv /usr/local/mysql/data/ib_logfile1 /usr/local/mysql/data/ib_logfile1.bak
sudo cp -a /usr/local/mysql/data/ibdata1.bak /usr/local/mysql/data/ibdata1
sudo cp -a /usr/local/mysql/data/ib_logfile0.bak /usr/local/mysql/data/ib_logfile0
sudo cp -a /usr/local/mysql/data/ib_logfile1.bak /usr/local/mysql/data/ib_logfile1
sudo /etc/init.d/mysql restart
share|improve this answer
"$ mysqld --skip-grant-tables" and " InnoDB: Unable to lock ./ibdata1, error: 35 InnoDB: Check that you do not already have another mysqld process InnoDB: using the same InnoDB data or log files. " ? – Vogelsire Jun 3 '13 at 7:42
see my update above – Yogus Jun 3 '13 at 7:45
I found that stopping mysql before issuing the 1st command stops the lock error from happening - service mysql stop – Frank Tzanabetis May 28 '15 at 3:09
Apparently the 'password' column no longer exists... it has been replaced by 'authentication_string'. So the password update string is now: UPDATE user SET authentication_string=PASSWORD('my_password') where USER='root'; – jdmcnair Dec 23 '15 at 17:03
@Yogus - is there a way to tell MySQL to honor Root (uid 0) rather than resetting a password? Resetting the password seems like its heavy handed when all I am trying to do is sudo mysqlcheck --all-databases. – jww Apr 1 at 22:30

Also make sure needed record in table user has empty plugin field (there can be, for example, "unix_socket").

Since version 5.5.7 mysql has various auth plugins support

So if you have non-empty plugin field then password would be ignored and there would be warning at mysql error log (for me it's /var/log/mysql/error.log):

[Warning] 'user' entry 'root@localhost' has both a password and an authentication plugin specified. The password will be ignored.

share|improve this answer

Try it:

mysql --no-defaults --force --user=root --host=localhost --database=mysql 
UPDATE user SET Password=PASSWORD('NEWPASSWORD') where USER='root';
share|improve this answer
Can you describe what the --no-defaults --force switches do? Otherwise, it's a VLQ duplicate of the above, accepted answer. – Canadian Luke Feb 21 '14 at 17:17
@CanadianLuke no defaults skips any configuration files present that it'd otherwise include, force continues operation even if any of the issued SQL commands fails. When in doubt, check the manual – deucalion May 26 '15 at 11:39
It needs to be edited in to the answer – Canadian Luke May 26 '15 at 14:31
I get ERROR 1054 (42S22): Unknown column 'Password' in 'field list' – Jonathan Leaders May 16 at 15:38
@JonathanLeaders look:… – Gustavo Duarte May 18 at 0:47
grep 'temporary password' /var/log/mysqld.log
Sort date (newest date)

You may see something like this;

[root@SERVER ~]# grep 'temporary password' /var/log/mysqld.log
2016-01-16T18:07:29.688164Z 1 [Note] A temporary password is generated for root@localhost: O,k5.marHfFu
2016-01-22T13:14:17.974391Z 1 [Note] A temporary password is generated for root@localhost: b5nvIu!jh6ql
2016-01-22T15:35:48.496812Z 1 [Note] A temporary password is generated for root@localhost: (B*=T!uWJ7ws
2016-01-22T15:52:21.088610Z 1 [Note] A temporary password is generated for root@localhost: %tJXK7sytMJV
2016-01-22T16:24:41.384205Z 1 [Note] A temporary password is generated for root@localhost: lslQDvgwr3/S
2016-01-22T22:11:24.772275Z 1 [Note] A temporary password is generated for root@localhost: S4u+J,Rce_0t
[root@SERVER ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password:

If you see it says

... Failed! Error: Your password does not satisfy the current policy requirements
That means your password needs to have a character such as ! . # - etc...
mix characters well, upper case, lower case, ! . , # etc...

New password: 

Re-enter new password: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...

 - Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

All done! 
[root@SERVER ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 MySQL Community Server (GPL)

Credit; Watch the last 10 minutes of this video it teaches you how you do it Subscribe to her youtube channel. She is a real professional. I subscribed.

share|improve this answer
Although this may answer the question, you should give a more detailed description of the linked content and explain how it relates to the question. This will help ensure that this answer remains useful in the event the linked page is removed or goes offline. For more information, see this Meta Stack Exchange post. – bwDraco Jan 22 at 23:15
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Ben N Jan 22 at 23:26
This is the use case I saw, I'm installing mysql on RHEL7 in AWS with Ansible and I'm getting the same behavior after reconfiguring and restarting the DB. Do you know why this happens on the first place, is blocking Ansible from accessing the local mysqld and configuring it. This is just for testing purposes. – einarc May 13 at 21:43
Apparently it depends on how you initialize the server, look at step 4 here:… – einarc May 13 at 21:48

You must log in to answer this question.

protected by bwDraco Jan 22 at 23:15

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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