Advertisement
Guest User

Untitled

a guest
Jan 6th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems
  2. On Unix, use the following procedure to reset the password for the MySQL 'root'@'localhost' account. To change the password for a root account with a different host name part, modify the instructions to use that host name.
  3.  
  4. The instructions assume that you will start the MySQL server from the Unix login account that you normally use for running it. For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you will need to either change the ownership of the files to mysql or remove them.
  5.  
  6. Log on to your system as the Unix user that the MySQL server runs as (for example, mysql).
  7.  
  8. Stop the MySQL server if it is running. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.
  9.  
  10. Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file in the following command:
  11.  
  12. shell> kill `cat /mysql-data-directory/host_name.pid`
  13. Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.
  14.  
  15. Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.
  16.  
  17. MySQL 5.7.6 and later:
  18.  
  19. ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  20. MySQL 5.7.5 and earlier:
  21.  
  22. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
  23. Save the file. This example assumes that you name the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions that permit mysql to read it.
  24.  
  25. Start the MySQL server with the special --init-file option:
  26.  
  27. shell> mysqld --init-file=/home/me/mysql-init &
  28. The server executes the contents of the file named by the --init-file option at startup, changing the 'root'@'localhost' account password.
  29.  
  30. Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.
  31.  
  32. After the server has started successfully, delete /home/me/mysql-init.
  33.  
  34. You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.
  35.  
  36. If the ALTER USER statement fails to reset the password, try repeating the procedure using the following statements to modify the user table directly:
  37.  
  38.  
  39. UPDATE mysql.user
  40. SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
  41. WHERE User = 'root' AND Host = 'localhost';
  42. FLUSH PRIVILEGES;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement