Resetting Forgotten MySQL Passwords

If you’ve forgotten a MySQL user password, you can log in to the server as the MySQL root user and update the password manually. If you’ve forgotten the root password, you’ll need to stop the server and restart it in a special way to allow you to change the root password.

The server is normally stopped with the mysqladmin shutdown command, but you can’t use this command if you’ve forgotten the MySQL root user password. Instead, you’ll need to use the /etc/init.d/mysql or /etc/init.d/mysqld script under Linux, the MySQL_Directory/scripts/mysql.server under Linux or Mac OS X, the MySQL preferences pane under Mac OS X, or the Windows Services window to shut down the server. If none of these are available, you can forcibly end or kill the server process, though this is not recommended since it can lead to data loss. You will need to have sufficient authorization to kill the server process, so you should be logged in under the same username the server is running under—for example, mysql, or your own account if the server is running under your username—or as a superuser (system root or Windows administrator).

To kill the server under Linux or Mac OS X, you should first determine the process identifier (or PID) of the server process. The PID is normally stored under the server data directory in a file with the extension .pid. You can list the contents of this file using the cat command and enclose the command in backtick symbols (`) to pass the output ...

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.