Reset the Root Password of MySQL Server重置root密碼的MySQL服務器
By default, MySQL Server will be installed with root superuser without any password.默認情況下, MySQL服務器將被安裝以root超級無任何密碼。 You can connect to MySQL server as root without requiring password or by keying in blank password.您可以連接到MySQL服務器,以root的身份,而不需要密碼或由鍵控在空白密碼。 However, if you have set the password for root and forget or unable to recall the password, then you will need to reset the root password for MySQL.不過,如果您有設定密碼為根,忘記或無法記得密碼,然後您將需要重置root密碼為MySQL開發。
MySQL Reference Manual has detail steps on how to reset password for root which are as below: MySQL的參考手冊有詳細的步驟,就如何重設密碼為根,這是作為如下:
The procedure under Windows:程序在Windows下:
- Log on to the Windows system where MySQL is running as Administrator.登錄到Windows系統的情況下運行的MySQL管理員。
- Stop the MySQL server if it is running.停止MySQL服務器,如果它正在運行。 For a server that is running as a Windows service, go to the Services manager:一台服務器正在運行作為Windows服務,轉到服務經理:
Start Menu -> Control Panel -> Administrative Tools -> Services開始菜單-> “控制面板- >”管理工具“- >服務
Then find the MySQL service in the list, and stop it.然後找到MySQL的服務列表中,並阻止它。
If your server is not running as a service, you may need to use the Task Manager to force it to stop.如果您的服務器運行的不是作為一種服務,您可能需要使用任務管理,迫使它停止。
- Create a text file and place the following command within it on a single line:創建一個文本文件,把下面的命令與它在一個單一的路線:
SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’MyNewPassword’);設置密碼為'根' @ '本地' =密碼( ' mynewpassword ' ) ;
Save the file with any name.保存該文件以任何名義。 For this example the file will be C:\mysql-init.txt.在這個範例中的文件將是C : \ MySQL的- init.txt 。
- Open a console window to get to the DOS command prompt:打開一個控制台窗口,以獲得向DOS命令提示符下:
Start Menu -> Run -> cmd開始菜單-> “運行- >” c m d
- If MySQL is installed in C:\mysql.如果MySQL的安裝在C : \ MySQL的。 If MySQL is installed in another location, adjust the following commands accordingly.如果MySQL的是安裝在另一個位置,調整下列命令。
At the DOS command prompt, execute this command:在DOS命令提示符下,執行此命令:
C:\> C:\mysql\bin\mysqld-nt –init-file=C:\mysql-init.txt為C : \ >為C : \ MySQL的\斌\ mysqld - NT下的init文件=為C : \ MySQL的- init.txt
The contents of the file named by the –init-file option are executed at server startup, changing the root password.該文件的內容命名- init的文件選項是執行在服務器啟動,改變了root密碼。 After the server has started successfully, you should delete C:\mysql-init.txt.之後,服務器已成功啟動,您應該刪除為C : \ MySQL的- init.txt 。
If you installed MySQL using the MySQL Installation Wizard, you may need to specify a –defaults-file option:如果您安裝了MySQL使用MySQL安裝嚮導,您可能需要指定一個-默認文件選項:
C:\> “C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe”為C : \ >的“ C : \程序文件\ MySQL的\ MySQL服務器5.0 \斌\ mysqld - nt.exe ”
–defaults-file=”C:\Program Files\MySQL\MySQL Server 5.0\my.ini” -默認文件= “為C : \程序文件\ MySQL的\ MySQL服務器5.0 \ my.ini ”
–init-file=C:\mysql-init.txt - init的文件=為C : \ MySQL的- init.txtThe appropriate –defaults-file setting can be found using the Services Manager:適當-默認文件設置可發現使用的服務經理:
Start Menu -> Control Panel -> Administrative Tools -> Services開始菜單-> “控制面板- >”管理工具“- >服務
Find the MySQL service in the list, right-click on it, and choose the Properties option.找到MySQL的服務列表中,右鍵單擊它,選擇屬性選項。 The Path to executable field contains the –defaults-file setting.路徑的可執行字段包含-默認文件的設置。 Be sure to supply the –init-file argument with the full system path to the file, regardless of your current working directory一定要供應- init的文件的說法與完整的系統文件的路徑,無論您的當前工作目錄
- Stop the MySQL server, then restart it in normal mode again.停止MySQL服務器,然後重新啟動它在正常模式下一次。 If the MySQL server is ran as a service, start it from the Windows Services window.如果MySQL服務器是然作為一個服務,啟動它從Windows服務的窗口。 If you start the server manually, use whatever command you normally use.如果你啟動服務器手動,使用什麼命令,通常您可使用。
- Connect to MySQL server by using the new password.連接到MySQL服務器使用新的密碼。
For Unix environment, the procedure for resetting the root password is as follows:為Unix環境,程序重置root密碼是如下:
- Log on to the Unix system as either the Unix root user or as the same user that the mysqld server runs as.登錄到UNIX系統作為Unix的root用戶或為同一用戶認為mysqld服務器運行。
- Locate the .pid file that contains the server’s process ID.找到。 PID的檔案,其中包含了服務器的進程ID 。 The exact location and name of this file depend on your distribution, hostname, and configuration.確切的位置和名稱,此文件取決於您的分佈,主機名稱,和配置。 Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/.常見的地點是到/ var / lib / MySQL的/和/ var /運行/ mysqld / ,和/ usr / local / MySQL的/數據/ 。 Generally, the filename has the extension of .pid and begins with either mysqld or the system’s hostname.一般來說,文件名的擴展。 PID控制,並開始與任何mysqld或系統的主機名。
Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the pathname of the .pid file in the following command:停止MySQL服務器發送一個正常的殺(不殺-9 )到mysqld過程中,使用的路徑的。 PID的文件在以下命令:
shell> kill `cat /mysql-data-directory/host_name.pid`蜆殼>殺人`貓/ mysql-data-directory/host_name.pid `
Note the use of backticks rather than forward quotes with the cat command; these cause the output of cat to be substituted into the kill command.注意使用backticks ,而非提出的報價與貓的指揮;這些事業的輸出貓被替換成KILL命令。
- Create a text file and place the following command within it on a single line:創建一個文本文件,把下面的命令與它在一個單一的路線:
SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’MyNewPassword’);設置密碼為'根' @ '本地' =密碼( ' mynewpassword ' ) ;
Save the file with any name.保存該文件以任何名義。 For this example the file will be ~/mysql-init.在這個範例文件將〜 / MySQL的-的init 。
- Restart the MySQL server with the special –init-file=~/mysql-init option:重新啟動MySQL服務器與特殊的init文件= 〜 / MySQL的- init的選項:
shell> mysqld_safe –init-file=~/mysql-init &蜆殼> mysqld_safe - init的文件= 〜 / MySQL的-的init &
The contents of the init-file are executed at server startup, changing the root password.內容的Init文件的執行在服務器啟動,改變了root密碼。 After the server has started successfully you should delete ~/mysql-init.之後,服務器已成功啟動您應該刪除〜 / MySQL的-的init 。
- Connect to MySQL server by using the new password.連接到MySQL服務器使用新的密碼。
Alternatively, on any platform, mysql client can be used to set the new password, althought it’s less secure way of resetting the password (detailed instruction另外,任何平台上, MySQL客戶端可以用來設置新的密碼,雖然它的安全性較低的方式重設密碼(詳細指示 here這裡 ): ) :
- Stop mysqld and restart it with the –skip-grant-tables –user=root options (Windows users omit the –user=root portion).停止mysqld並重新啟動它與-跳過-贈款表用戶=根選項( Windows用戶省略-用戶=根部分) 。
- Connect to the mysqld server with this command:連接到mysqld服務器與此命令:
shell> mysql -u root蜆殼> MySQL的中美根
- Issue the following statements in the mysql client:發出以下聲明在MySQL客戶端:
mysql> UPDATE mysql.user SET Password=PASSWORD(’newpwd’) MySQL的>更新mysql.user設置密碼=密碼( ' newpwd ' )
-> WHERE User=’root’; -> “其中u ser= '根' ;
mysql> FLUSH PRIVILEGES; MySQL的>沖水特權;Replace ‘newpwd’ with the actual root password that you want to use.取代' newpwd '與實際root密碼您想要使用的。
- You should be able to connect using the new password.您應該可以連接使用新的密碼。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明 :這是一個機器翻譯網頁是“按原樣”提供的擔保。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article原來的英語文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和貢獻,或取得技術的支持和幫助,在 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- Change and Reset MySQL root Password改變和重置MySQL的root密碼
- Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - Part 3安裝Web服務器在FreeBSD的6.0與2.2的Apache , MySQL 5.0的和PHP 5 -第3部分
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4安裝Web服務器在Windows XP的Apache2 , php5和mysql4 -第4部分
- Check and Optimize MySQL Database Automatically with Crontab/Cron檢查和優化MySQL數據庫自動與crontab /玉米
- Using phpMyAdmin for Effective MySQL Management in Windows XP使用phpmyadmin有效MySQL的管理在Windows XP
- Fix for Munin MySQL Monitoring Plugin Graph Not Showing or Blank修復munin MySQL的監測插件圖無法顯示或空白
- How to Reset WordPress Password to Recover Forgotten Secret如何重置的WordPress密碼,以收回被遺忘的秘密
- How to Reset AdSense Password Not Associated with Google Account如何重置AdSense密碼不能與Google相關的帳戶
- Disable Direct Root Login and User Access via SSH to Server禁用直接根登錄和用戶接入通過SSH服務器
- Install phpBB 2 in Windows XP running on Apache 2, PHP 5 and MySQL 4安裝phpbb 2在Windows XP上運行的Apache 2 , PHP 5中和MySQL 4

































June 6th, 2006 18:12 2006年6月6日18時12分
[...] Other then the ways specified here to reset and change the root password for mySQL database in the case that the password is forgotten or lost, the following instructions explain in details the alternative way at the last part of the guide, where no additional file needs to be created: [...] [ … … ] ,然後其他的方式指定在這裡重置和改變了root密碼為MySQL數據庫,在案件的密碼是忘記或遺失,下列指示解釋,在細節的替代方式,在上次的一部分,指導,凡沒有額外的文件需要建立: [ … … ]
October 8th, 2007 03:47 2007年10月8日3時47分
You should add –verbose –console to the command in step 5.你應該添加-詳細-控制台命令在第5步。 I got a error because of a copy and paste issue that include a quote of the wrong type but there’s no error feedback without the –console.我得到錯誤,因為一個複製並粘貼的問題,包括引用了錯誤的類型,但有沒有錯誤的反饋意見,未經控制台。 Also, the -console to stop the server with CTRL-C under windows, not sure about linux.此外,控制台停止服務器與按Ctrl - C的Windows環境下,不知道的Linux 。
-Mike -麥克
April 23rd, 2008 23:38 2008年4月23日23時38分
This isn’t correct.這是不正確的。 The syntax should be “–init” not “-init”.語法應該是“ - init的”不“ -的init ” 。
April 23rd, 2008 23:39 2008年4月23日23時39分
Ah and now that I’ve posted I see the problem.啊,現在我已張貼我看到這個問題。 This site is disallowing double “-”.這個站點是不允許的雙重“ -” 。 It’s being escaped or something.它的被逃脫或東西。
Well dear reader, just now that “-init” should have TWO dashes (hyphens), not one.以及親愛的讀者,只是現在“的init ”應該有兩個破折號(連字號) ,而不是1 。
April 23rd, 2008 23:39 2008年4月23日23時39分
Gah. gah 。 “know” not “now”. “知道” ,而不是“現在” 。 I’m going for coffee now.我會為現在的咖啡。
April 24th, 2008 10:05 2008年4月24日10時05分
Dude,紈絝子弟,
Didn’t see these comments while reading the article, but I figured out the double-hyphen syntax by trial and error.沒有看到這些評論的同時,讀文章,但我揣摩雙連字符語法審判和錯誤。
Anyway you saved my Life by putting this documentation on the Net !!無論如何,你救了我的生活把這個文件就淨! A thousand thanks ! 1000謝謝! -Rob -白俄羅斯共和國
April 25th, 2008 01:37 2008年4月25日1時37分
There is a typo on the mysqld startup script.有一個錯字就啟動腳本mysqld 。
The correct command requires TWO dashes before the parameter setting.正確的命令需要兩個破折號之前的參數設置。
The correct command is (note TWO dashes before skip-grant-tables):正確的命令是(請注意,兩個破折號之前跳過-贈款表) :
mysqld_safe –skip-grant-tables mysqld_safe -跳過-贈款表
July 31st, 2008 21:18 2008年7月31日21時18分
Procdure to reset root password in MySQL [RedHat & Fedora] procdure重置root密碼在MySQL [版RedHat & Fedora的]
====================================================== ================================================== ====
Step-1步驟- 1
[root@redhat~]#killall mysqld [根@ Redhat的〜 ] # killall mysqld
[root@redhat~]#/usr/libexec/mysqld –skip-grant-tables –user=root & [根@ Redhat的〜 ] #是/ usr / libexec / mysqld -跳過-贈款表用戶=根&
====================================================== ================================================== ====
Step-2 (In MySQL)步驟- 2 (在MySQL )
[root@redhat~]#mysql [根@ Redhat的〜 ] # MySQL的
use mysql;使用MySQL ;
update user set password=password(”newpassowrd”) where user=”root”;更新用戶設置密碼=密碼( “ newpassowrd ” )凡用戶= “根” ;
flush privileges;沖水特權;
exit;退出;
====================================================== ================================================== ====
Step-3步驟- 3
[root@redhat~]#killall mysqld [根@ Redhat的〜 ] # killall mysqld
[root@redhat~]#/etc/init.d/mysqld start [根@ Redhat的〜 ] # / etc / init.d /的mysqld啟動
There you go在那裡,您去
August 14th, 2008 10:47 2008年8月14日10時47分
phpmyadmin