Saturday 4 October 2014

Change the MySQL root Password

How to Change the MySQL root Password in Linux or OSX via Command Line



If you have forgot the MySQL root password, can’t remember 
And want to break in…..



Stop MySQL

root@server:~# /usr/local/mysql/support-files/mysql.server stop

                                                   OR
root@server:~# /etc/init.d/mysqld stop
   

Start it in safe mode:
root@server:~# mysqld_safe --skip-grant-tables




This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:


root@server:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; 
mysql> Change the lowercase password to what you want – with single quotes.
 

mysql> FLUSH PRIVILEGES;mysql> quit

   



Start MySQL

 
root@server:~# /usr/local/mysql/support-files/mysql.server start

                          OR 
root@server:~# /etc/init.d/mysqld start
 



























































































































































































































No comments:

Post a Comment