Guest User

Untitled

a guest
Jan 8th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. # Recover MySQL root password
  2.  
  3. You can recover a MySQL database server password with the following five easy steps:
  4.  
  5. 1. Stop the MySQL server process.
  6. 1. Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for a password.
  7. 1. Connect to the MySQL server as the root user.
  8. 1. Set a new root password.
  9. 1. Exit and restart the MySQL server.
  10.  
  11. Here are the commands you need to type for each step (log in as the root user):
  12.  
  13. ## Step # 1: Stop the MySQL service:
  14.  
  15. `service mysqld stop`
  16.  
  17. Output:
  18. ```
  19. Stopping MySQL database server: mysqld.
  20. ```
  21.  
  22. ## Step # 2: Start the MySQL server w/o password:
  23.  
  24. `mysqld_safe --skip-grant-tables &`
  25.  
  26. Output:
  27. ```
  28. [1] 5988
  29. Starting mysqld daemon with databases from /var/lib/mysql
  30. mysqld_safe[6025]: started
  31. ```
  32.  
  33. ## Step # 3: Connect to the MySQL server using the MySQL client:
  34.  
  35. `mysql -u root`
  36.  
  37. Output:
  38.  
  39. ```
  40. Welcome to the MySQL monitor. Commands end with ; or \g.
  41. Your MySQL connection id is 56299
  42. Server version: 5.6.34-1 (Debian)
  43.  
  44. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  45.  
  46. Oracle is a registered trademark of Oracle Corporation and/or its
  47. affiliates. Other names may be trademarks of their respective
  48. owners.
  49.  
  50. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  51.  
  52.  
  53. mysql>
  54. ```
  55.  
  56. ### Step # 4: Set a new MySQL root user password:
  57. ```
  58. mysql> use mysql;
  59. mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
  60. mysql> quit
  61. ```
  62.  
  63. ## Step # 5: Stop the MySQL server:
  64.  
  65. `service mysqld stop`
  66.  
  67. Output:
  68. ```
  69. Stopping MySQL database server: mysqld
  70. STOPPING server from pid file /var/run/mysqld/mysqld.pid
  71. mysqld_safe[6186]: ended
  72.  
  73. [1]+ Done mysqld_safe --skip-grant-tables
  74. ```
  75.  
  76. The output might differ based on the Linux distribution. Don't worry unless it reports an error. Start the MySQL server and test it:
  77.  
  78. `service mysqld start`
  79.  
  80. `mysql -u root -p`
Add Comment
Please, Sign In to add comment