1.mysqladmin -uroot -poldpassword password newpassword
2.mysql> update mysql.user set password=PASSWORD('新密碼') where User='root';
mysql> flush privileges;
mysql> quit
3.mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='name';
mysql> FLUSH PRIVILEGES;
mysql> QUIT
4.可以修改MYSQL檔案夾中的MY.INI檔案
5.使用SET PASSWORD語句,
mysql> SET PASSWORD FOR myuser@localhost = PASSWORD('mypasswd');
6.使用GRANT ... IDENTIFIED BY語句
mysql> GRANT USAGE ON *.* TO myuser@localhost IDENTIFIED BY 'mypassword';
在windows下:
開啟命令列視窗,停止mysql服務:Net stop mysql
到mysql的安裝路徑啟動mysql,在bin目錄下使用mysqld-nt.exe啟動,在命令列視窗執行:mysqld-nt --skip-grant-tables
然後另外開啟一個命入令行視窗,執行mysql,此時無需輸入密碼即可進入。
>use mysql
>update user set password=password("new_pass") where user="root";
>flush privileges;
>exit
使用工作管理員,找到mysqld-nt的進程,結束進程!
在重新啟動mysql-nt服務,就可以用新密碼登入了。
在linux下:
如果 MySQL 正在運行,首先殺之: killall -TERM mysqld。
啟動 MySQL :bin/safe_mysqld --skip-grant-tables &
就可以不要求輸入密碼就進入 MySQL 了。
然後就是
>use mysql
>update user set password=password("new_pass") where user="root";
>flush privileges;
重新殺 MySQL ,用正常方法啟動 MySQL 。
1)停止windows服務中的mysql執行個體
2)使用–skip-grant-tables 參數啟動mysql,這種模式下,無需root密碼就可以登陸mysql.
mysqld-max-nt –skip-grant-tables
3)登陸mysql,修改密碼
C:\Documents and Settings\binzhang>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.27-community-max-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql;
Database changed
mysql> update user set password=password("root") where user="root";
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0