Advertisement
june23rd1987

CENTOS 7 MYSQL RESET

Mar 15th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1.  
  2. What version of mySQL are you using? I''m using 5.7.10 and had the same problem with logging on as root
  3.  
  4. There is 2 issues - why can't I log in as root to start with, and why can I not use 'mysqld_safe` to start mySQL to reset the root password.
  5.  
  6. I have no answer to setting up the root password during installation, but here's what you do to reset the root password
  7.  
  8. Edit the initial root password on install can be found by running
  9.  
  10. grep 'temporary password' /var/log/mysqld.log
  11.  
  12. http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
  13.  
  14. systemd is now used to look after mySQL instead of mysqld_safe (which is why you get the -bash: mysqld_safe: command not found error - it's not installed)
  15.  
  16. The user table structure has changed.
  17.  
  18. So to reset the root password, you still start mySQL with --skip-grant-tables options and update the user table, but how you do it has changed.
  19.  
  20. 1. Stop mysql:
  21. systemctl stop mysqld
  22.  
  23. 2. Set the mySQL environment option
  24. systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
  25.  
  26. 3. Start mysql usig the options you just set
  27. systemctl start mysqld
  28.  
  29. 4. Login as root
  30. mysql -u root
  31.  
  32. 5. Update the root user password with these mysql commands
  33. mysql> UPDATE mysql.user SET authentication_string = PASSWORD('200504533Aa@') WHERE User = 'root' AND Host = 'localhost';
  34. mysql> FLUSH PRIVILEGES;
  35. mysql> quit
  36.  
  37. *** Edit ***
  38. As mentioned my shokulei in the comments, for 5.7.6 and later, you should use
  39. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '200504533Aa@';
  40. Or you'll get a warning
  41.  
  42. 6. Stop mysql
  43. systemctl stop mysqld
  44.  
  45. 7. Unset the mySQL envitroment option so it starts normally next time
  46. systemctl unset-environment MYSQLD_OPTS
  47.  
  48. 8. Start mysql normally:
  49. systemctl start mysqld
  50.  
  51. Try to login using your new password:
  52. 7. mysql -u root -p
  53.  
  54. Reference
  55.  
  56. As it says at http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement