No MySQL users after fresh install in RHEL 6.6

I had a fresh install of RHEL 6.6 with MySQL 5.1.73. When i tried to reset MySQL root password for MySQL, it hadn’t worked. Reason was, that mysql.user table was empty, there was no ‘root’ user created.

Following helped me to resolve the issue:

  1. Restart MySQL like this:
    service mysqld restart --skip-grant-tables
     
  2. Enter MySQLfrom the command line (no password needed at this point)
    # mysql
     
  3. Do desc mysql.user
     

    You will see 17 rows for MySQL 4.1
    You will see 37 rows for MySQL 5.0
    You will see 39 rows for MySQL 5.1
    You will see 42 rows for MySQL 5.5

    You will have to tweak each privilege since the GRANT command does not work will skip-grant-tables is enabled

  4. For MySQL 5.1, you can enter a new root@localhost whose password is ‘whatever’ as follows:
     

    DELETE FROM mysql.user WHERE user='root' AND host='localhost';
    INSERT INTO mysql.user SET
                      Host = 'localhost',
                      User = 'root',
                  Password = PASSWORD('whatever'),
               Select_priv = 'Y',
               Insert_priv = 'Y',
               Update_priv = 'Y',
               Delete_priv = 'Y',
               Create_priv = 'Y',
                 Drop_priv = 'Y',
               Reload_priv = 'Y',
             Shutdown_priv = 'Y',
              Process_priv = 'Y',
                 File_priv = 'Y',
                Grant_priv = 'Y',
           References_priv = 'Y',
                Index_priv = 'Y',
                Alter_priv = 'Y',
              Show_db_priv = 'Y',
                Super_priv = 'Y',
     Create_tmp_table_priv = 'Y',
          Lock_tables_priv = 'Y',
              Execute_priv = 'Y',
           Repl_slave_priv = 'Y',
          Repl_client_priv = 'Y',
          Create_view_priv = 'Y',
            Show_view_priv = 'Y',
       Create_routine_priv = 'Y',
        Alter_routine_priv = 'Y',
          Create_user_priv = 'Y',
                Event_priv = 'Y',
              Trigger_priv = 'Y',
                  ssl_type = '',
                  ssl_cipher = '',
                 x509_issuer = '',
                x509_subject = '',
               max_questions = 0,
                 max_updates = 0;

  5. Restart MySQL
    service mysqld restart

Source: Database Administrators Stack Exchange

Published by

jiri.janak

IT Specialist, Sportsman, Photographer and Dreamer