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

Unfortunately I deleted MySQL users with the command

delete from mysql.user

and now I can't access MySQL. I tried looking at MySQL - ERROR 1045 - Access denied, but it is not proper for me because I don't have any user for MySQL.

I uninstalled and reinstalled MySQL but I can't access MySQL. What should I do? I wanted to have phpMyAdmin without login and I ruined the whole thing.

After uninstalling and having no result, I tried to delete the directories of MySQL and again installing them but again no result and now I have this error:

Error 2002:can't connect to local mysql server through socket /var/lib/mysql/mysql.sock

I don't have any user to reset the password of, but if I have by reinstalling which I don't know how to connect to MySQL.

  • I tried MySQL -u root
  • I tried MySQL
  • I tried mysqld-safe and etc in the link
share|improve this question
    
Your title says you deleted root but you mention mysql which account did you delete exactly. If it wasn't root just use root to add a new mysql user. – Ramhound Aug 13 '12 at 13:06
    
I issued this command delete from mysql.users so I deleted the whole users – Negin Nicki Aug 13 '12 at 13:10
    
I screwed the whole – Negin Nicki Aug 13 '12 at 13:12
    
I restarted the system and it finally goes to the system I don't know what the hell is happening here – Negin Nicki Aug 13 '12 at 13:17
    
What about a fresh MySQL install in a different directory (or computer) and then replacing the data files (empty) with your old ones? – golimar Aug 13 '12 at 15:39

I'd like to recommend something more secure

STEP 01 : Create a File That Puts Back the root@localhost with the password wh@t3v3r

cd /var/lib/mysql
echo "GRANT ALL PRIVILEGES ON *.* TO root@localhost " > InitFile.sql
echo "IDENTIFIED BY 'wh@t3v3r';" >> InitFile.sql

STEP 02 : Add the following to /etc/my.cnf under the [mysqld] group

[mysqld]
init-file=/var/lib/mysql/InitFile.sql

STEP 03 : service mysql restart

STEP 04 : Remove init-file=/var/lib/mysql/InitFile.sql from /etc/my.cnf

STEP 05 : rm -f /var/lib/mysql/InitFile.sql

If you can connect to mysql like this:

mysql -uroot -p <hit enter>
Password: <type password wh@t3v3r and hit enter>

CONGRATULATIONS !!!

share|improve this answer

mysqld has a --skip-grant-tables option, you may try restarting it that way. Then you'd restore data from a backup.

share|improve this answer

You must log in to answer this question.

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