關閉正在運行的 MySQL :mysql
[root@www.woai.it ~]# service mysql stopsql
運行數據庫
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables &安全
爲了安全能夠這樣禁止遠程鏈接:ide
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables --skip-networking &ui
使用mysql鏈接server:加密
[root@www.woai.it ~]# mysql -p.net
更改密碼:rest
mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';server
*特別提醒注意的一點是,新版的mysql數據庫下的user表中已經沒有Password字段了
而是將加密後的用戶密碼存儲於authentication_string字段
mysql> flush privileges;
mysql> quit;
修改完畢。重啓
[root@localhost ~]# service mysql restart
而後mysql就能夠鏈接了
但此時操做彷佛功能不徹底,還要alter user…
mysql> alter user 'root'@'localhost' identified by '123';
這樣也能夠:
mysql> set password for 'root'@'localhost'=password('123');