Step1: Stop MySQL Server(service mysql stop /mysqladmin –u root –p shoutdown)
Step2: Add –skip-grant-tables to mysqld_safe Startup Command.Open the mysql startup script and add -skip-grant-tables as shown below.( vi /etc/rc.d/init.d/mysql)
Old Line: $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
New Line: $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
Step3: Start MySQL Server With –skip-grant-tables Start the mysql server with skip-grant-tables option, which will allow anybody to login to mysql without entering a password.( service mysql start)
Step4: Login Using MySQL Root User Without Entering Password(mysql -u root mysql)
Step5: Set MySQL Root Password to a New Password Using UPDATE Command
UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
flush privileges;
Step6: Stop the MySQL Server(service mysql stop)
Step7: Update /etc/rc.d/init.d/mysql Startup Script and Remove –skip-grant-table(vi /etc/rc.d/init.d/mysql)
Old Line: $bindir/mysqld_safe --skip-grant-tables --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
New Line: $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
Step8: Start MySQL Server(service mysql start)
Step9: Login to MySQL With the New Password(mysql -u root -pnewpassword)
No comments:
Post a Comment