Skip to content

Instantly share code, notes, and snippets.

@comodinx
Last active November 30, 2021 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comodinx/50bb9173ef18ae3ca00948260ec3a3ea to your computer and use it in GitHub Desktop.
Save comodinx/50bb9173ef18ae3ca00948260ec3a3ea to your computer and use it in GitHub Desktop.
Fixed when the root user disappears on MySQL.

Fixed when the root user disappears.

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

  1. Stop MySQL service (in my case, is installed with brew)

    brew services stop mysql
  2. Start MySQL safe

    mysqld_safe --skip-grant-tables
  3. Connect to MySQL with

    mysql
  4. Execute next scripts ↓

    Pass: for your password, use: MySQL < 8

    SELECT PASSWORD('mypass');

    MySQL >= 8

    SELECT CONCAT('*', UPPER(SHA1(UNHEX(SHA1('mypass')))));
    USE mysql;
    insert into `user` VALUES('%','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','0x','0x','0x',0,0,0,0,'mysql_native_password','*DA7A8D7CA47235D5970C15CB43228E28671B9872','N','2021-09-27 14:24:45',NULL,'N','Y','Y',NULL,NULL,NULL,NULL);
  5. Stop MySQL safe

    killall mysqld
  6. Start MySQL service

    brew services start mysql
  7. All is ready. To enjoy mysql again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment