方法1: 用SET PASSWORD命令mysql
mysql -u rootsql
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');spa
方法2:用mysqladminorm
mysqladmin -u root password "newpass"ip
若是root已經設置過密碼,採用以下方法it
mysqladmin -u root password oldpass "newpass"table
方法3: 用UPDATE直接編輯user表密碼
mysql -u root方法
mysql> use mysql;margin
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丟失root密碼的時候,能夠這樣
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;