Mysql Password Management
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES;
A. Change password using command: In Linux:
Login to the MySQL server from the command line with the following command:
mysql -u root -p
Now switch to the appropriate MySQL database with the following command:
use mysql;
Next we’ll update the password for all MySQL users with the name root . Be sure to replace your_new_password with the actual new password:
update user set password=PASSWORD('your_new_password') where User='root';
Note: You can change the password for any user with the above command. Simply specify that user’s username in place of root .
Finally, reload the privileges:
flush privileges;
Now you’re all set to exit MySQL!
quit
mysql -u root -p
Now switch to the appropriate MySQL database with the following command:
use mysql;
Next we’ll update the password for all MySQL users with the name root . Be sure to replace your_new_password with the actual new password:
update user set password=PASSWORD('your_new_password') where User='root';
Note: You can change the password for any user with the above command. Simply specify that user’s username in place of root .
Finally, reload the privileges:
flush privileges;
Now you’re all set to exit MySQL!
quit
B. Recover MySQL root Password
1. Stop mysql service
/etc/init.d/mysql stop
/etc/init.d/mysql stop
2. Start to MySQL server w/o password:
Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password
mysqld_safe --skip-grant-tables &
mysqld_safe --skip-grant-tables &
3. Connect to mysql server using mysql client as root:
mysql -u root
mysql -u root
4. Setup new MySQL root user password:
Setup new mysql root account password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
5. Stop MySQL Server:
/etc/init.d/mysql stop
/etc/init.d/mysql stop
6. Start MySQL server and test it
C. Reset Passwd using Mysql Manual
1. Log on to your system as Administrator.
2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
If your server is not running as a service, you may need to use the Task Manager to force it to stop.
3. Create a text file containing the following statements. Replace the password with the password that you want to use.
UPDATE
mysql.
user
SET
Password=PASSWORD(
'MyNewPass'
)
WHERE
User
=
'root'
;
FLUSH PRIVILEGES;
Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
4. Save the file. For this example, the file will be named C:\mysql-init.txt.
5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):
C:\> C:\mysql\bin\mysqld
--init-file=C:\\mysql-init.txt
If
you installed MySQL
to
a location other than C:\mysql, adjust the command accordingly.
The server executes the contents
of
the
file
named
by
the
--init-file option at startup, changing each root account password.
You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.
If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:
C:\>
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld.exe"
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.5\\my.ini"
--init-file=C:\\mysql-init.txt
The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.
7.
After the server has started successfully,
delete
C:\mysql-init.txt.
Add mysql to startup of linux
1. Log on to your system as Administrator.
2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
If your server is not running as a service, you may need to use the Task Manager to force it to stop.
3. Create a text file containing the following statements. Replace the password with the password that you want to use.UPDATE
mysql.
user
SET
Password=PASSWORD(
'MyNewPass'
)
WHERE
User
=
'root'
;
FLUSH PRIVILEGES;Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
4. Save the file. For this example, the file will be named C:\mysql-init.txt.
5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):
C:\> C:\mysql\bin\mysqld
--init-file=C:\\mysql-init.txt
If
you installed MySQL
to
a location other than C:\mysql, adjust the command accordingly.
The server executes the contents
of
the
file
named
by
the
--init-file option at startup, changing each root account password.
You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file. If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:C:\>
"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld.exe"
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.5\\my.ini"
The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.
--init-file=C:\\mysql-init.txt
7.
After the server has started successfully,
delete
C:\mysql-init.txt.
Add mysql to startup of linux
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.