MySQL 5.7.6 and later:
alter user ‘root’@‘localhost’ identified by ‘新密碼’;
MySQL 5.7.5 and earlier:
set password for ‘root’@‘localhost’=password(‘新密碼’);
cd /usr/local/mysql/bin/
$ sudo su
# mysql_safe —init-file=/home/me/mysql-init &
#mysql_safe —skip-grant-tables &
#./mysql
#flush privileges
#update mysql.user set authentication_string = password(‘你在文件中定義的新密碼’),password_expired = ’N’ where user = ‘root’ and host = ‘localhost’
#flush privileges;
#quit;
#./mysql -u root -p
#輸入你的新密碼就好了
參考:B.5.3.2.2?Resetting the Root Password: Unix and Unix-Like Systems小節