You need to restart mysql from the Linux command line like this:
service mysql restart --skip-grant-tables --skip-networking
If you are using Windows, add the two options in the mysqld section of my.ini:
and then run
net stop mysql (wait 10 seconds)
net start mysql
This will allow immedidate login without authentication and without any remoye connection sneaking in on you.
INSERT INTO mysql.user SET
service mysql restart
At least you will have a localhost user named
mynewuser with enough privileges to login.
You should then run this query:
select user,host,password from mysql.user;
and see if any new users were added by a hacker. If you see any remote users that should not be there, you can remove them with:
DELETE FROM mysql.user WHERE ...;
If you are using Windows, please remember to remove
skip-networking from my.ini, then stop and start mysql service.
Make a backup of
/var/lib/mysql/mysql before you do anything.
UPDATE 2011-09-26 10:41 EDT
If the INSERT INTO mysql.user query does not work, it simply means the query is not compatible with the version of mysql I took this example from.
In order to know the correct INSERT query to user, please run this query:
You will see all columns with the type ENUM('Y','N') for each privilege. Adjust the INSERT query to match all columns and then run that INSERT.
To get the exact columns to set to Y for all privileges, user this query:
SELECT CONCAT('SET ... ',GROUP_CONCAT(CONCAT(column_name,'=''Y'''),';'))
ORDER BY ORDINAL_POSITION\G
This will present to columns to set regardless of the version of MySQL you are using.