How to access MySQL when I delete the root user on openSUSE 11?

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 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 reinstall 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 to reinstall, I don't know how to connect to MySQL, and have tried:

  • MySQL -u root
  • MySQL
  • mysqld-safe, etc. in the link

Solution 1:

I'd like to recommend something more secure:

  1. 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
    
  2. Add the following to /etc/my.cnf under the [mysqld] group
    [mysqld]
    init-file=/var/lib/mysql/InitFile.sql
    
  3. service mysql restart
  4. Remove init-file=/var/lib/mysql/InitFile.sql from /etc/my.cnf
  5. rm -f /var/lib/mysql/InitFile.sql

You can connect to mysql like this:

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