An example of a command to kill
a server running from the /usr/local/mysql directory would be
kill cat /usr/local/mysql/data/localhost.pid`If you specified a custom PID file location with the pid-file option, you’ll need to specify the same location here.
To
kill the server under Windows, press the Ctrl-Alt-Del keys together to open the Task
Manager, select the
mysqld-nt.exe entry under the Processes tab, and click on the End
Process button.
Once the server is stopped, you need to restart it and change the database root user password. There are two approaches that you can use. First, you can open a text editor and create a text file containing an SQL command to update the database root user password:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('
the_mysql_root_password');
Save
this file under the name reset_root_password.sql. Now, you need to start the
MySQL server with the init-file option, telling the server to execute
the commands in this file mysqld_safe --init-file=path_to_the_init_file &For example, on a Linux or Mac OS X system, with the file in the
/tmp directory, you would write
mysqld_safe --init-file=
/tmp/reset_root_password.sql &while on a Windows system with the file in the
C:\ directory, you would write:
C:\>
mysqld-nt --init-file=C:\reset_root_password.sql &Note that the server should have permission to access and read this file. If the server can’t
access the file, it will refuse to start and write a message such as this one in the server log 22:12:01 ERROR /usr/sbin/mysqld: File '/home/adam/tmp/reset_root_passwrd.sql'
not found (Errcode: Here, the name of the initialization file has been mistyped. Once you’ve started the server successfully, you should shut it down and start it again normally without the init-file option. You should then carefully delete the text file containing the password. If you drag and drop the file to the system Trashcan or Recycle Bin, empty this so that the file can’t be easily recovered. Even better, you should use a
file-wiping tool such as shred(under Linux and Mac OS Xor Eraser (under Windows) that ensures that sensitive files—and any temporary or backup files created by your text editor—
are destroyed when they are deleted.
An alternative approach is to start the server using the skip-grant-tables option. This tells the server not to check user passwords and access levels:
Share with your friends: