其設置密碼有三種方法:
a. ./mysqladmin -u root -p oldpassword newpasswd(記住這個命令是在/usr/local/mysql/bin中外部命令)
b. SET PASSWORD FOR root=PASSWORD(’new password’);(對登錄數據庫后這種方式)
c. UPDATE user SET password=PASSWORD(”new password”) WHERE user=’root’; (對登錄數據庫后這種方式)
看到評論區那么多人喊,我就更新一下吧。。。以下內容轉自網絡。。。
MySQL 5.7版本
版本更新后,原來user里的password字段已經變更為authentication_string
而且好多網上的教程都不適用了,甚至連官網的文檔也不是能夠順利操作的。
如果 MySQL 正在運行,首先殺之: killall -TERM mysqld。
運行mysqld_safe --skip-grant-tables &
如果此時不想被遠程連接:mysqld_safe --skip-grant-tables --skip-networking &
使用mysql連接server
更改密碼:update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
*特別提醒注意的一點是,新版的mysql數據庫下的user表中已經沒有Password字段了
而是將加密后的用戶密碼存儲於authentication_string字段
mysql> flush privileges;
mysql> quit;
修改完畢。重啟
killall -TERM mysqld。
mysqld_safe &
然后mysql就可以連接了
但是此時操作似乎功能不完全,還要alter user...
alter user 'root'@'localhost' identified by '123';
網文說醬紫也可以:set password for 'root'@'localhost'=password('123');
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql