Method 1. How to Change MySQL Root Password Using mysqladmin Command?
You can change the MySQL root password using mysqladmin command as
shown below. Please note that there is no space between -p and
currentpassword.
# mysqladmin -u root -pCURRENTPASSWORD password ‘NEWPASSWORD’
Once you’ve changed it make sure you can login with your new password successfully as shown below.
# mysql -u root -pnewpassword
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.5.13-rc-community MySQL Community Server (GPL)
mysql>
************************************************************************************************
Method 2. How to Change MySQL Root Password From MySQL Prompt Using UPDATE SQL Command?
You can also use the standard update SQL command combined with the
MySQL password function to change the password as shown below. Login to
MySQL root account using old password
# mysql -u root -poldpassword
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.5.13-rc-community MySQL Community Server (GPL)
mysql>
mysql> UPDATE user SET password=PASSWORD(‘newpassword’) WHERE user=’root’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Verify the new MySQL root password
Once you’ve changed it make sure you can login with your new password successfully as shown below.
# mysql -u root -pnewpassword
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.5.13-rc-community MySQL Community Server (GPL)
mysql>
************************************************************************************************
Method 3. How to Set MySQL Root Password Using mysqladmin Command?
This method works only if there is no password currently assigned for
the root account. If you don’t have any password assigned to the root
account, set the password without giving current password as shown
below.
# mysqladmin -u root password ‘newpassword’ [Note: There is no currentpassword for root in this example]
How to Change MySQL Regular User (non-root) Password Using mysqladmin Command?
# mysqladmin -u jsmith -pcurrentpassword password ‘newpassword’
How to Change MySQL Regular User (non-root) Password From MySQL Prompt Using UPDATE SQL Command?
mysql> UPDATE user SET password=PASSWORD(‘newpassword’) WHERE user=’ramesh’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
************************************************************************************************
Method 4. Recover MySQL Root Password
Step-1:- Stop mysql service
# /etc/init.d/mysql stop
Stopping MySQL database server: mysqld.
Step-2:- Start to MySQL server w/o password:
# mysqld_safe –skip-grant-tables &
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step-3:- Connect to mysql server using mysql client:
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 5.5.13-rc-community MySQL Community Server (GPL)
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql>
Step-4:- Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root’;
mysql> flush privileges;
mysql> quit
Step-5:- Stop MySQL Server:
# /etc/init.d/mysql stop
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe –skip-grant-tables
Step-6:- Start MySQL server and test it
# /etc/init.d/mysql start
# mysql -u root -p
Không có nhận xét nào:
Đăng nhận xét