修改MySQL密碼:
復制代碼 代碼如下:
mysqladmin -u root -p password 123456
mysqladmin -u用戶名 -p舊密碼 password 新密碼
忘記MySQL密碼:
復制代碼 代碼如下:
chown -R mysql:mysql /var/lib/mysql
/etc/init.d/mysql stop 或 kill -9 殺死進程。
[root@corshetlpro01 bin]# cd /usr/local/mysql/bin
./mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@corshetlpro01 bin]# ps -ef | grep mysql
root 26544 25356 0 15:08 pts/18 00:00:00 /bin/sh ./mysqld_safe --user=mysql --skip-grant-tables --skip-networking
mysql 26673 26544 0 15:08 pts/18 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql --skip-grant-tables --skip-networking --log-error=/var/lib/mysql/corshetlpro01.err --pid-file=/var/lib/mysql/corshetlpro01.pid --socket=/tmp/mysql.sock --port=3306
root 27223 25356 0 15:08 pts/18 00:00:00 grep mysql
./mysql -u root
mysql> use mysql;
mysql> update user set password=password('newpassword') where user='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
enter password: <輸入新設的密碼newpassword>