啟動後任何人均可無密碼連接數據庫(除非服務器屏蔽外網)。雖然重置時間短,但「不怕賊偷,就怕賊惦記」。
mysqld_safe --skip-grant-tables --skip-networking &
--skip-networking 禁用 TCP/IP 連接,僅允許本地 Unix Socket/管道,極大降低風險。
/path/to/init.sql:
UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;
/etc/init.d/mysql stopmysqld_safe --init-file=/path/to/init.sql &net stop mysqlD:\mysql5\bin(根據實際路徑):mysqld-nt --skip-grant-tables --skip-networkingmysqladmin -uroot flush-privileges password "newpassword"mysqladmin -u root -p shutdown(輸入新密碼)net start mysql官方文檔:How to Reset the Root Password。參數亦可寫入 my.cnf [mysqld] 區段。