2013-04-10 59 views
4

我是一個新手到Python,試圖通過編寫它連接到我們的MySQL數據庫,並做一些東西服務器腳本來學習一些東西。我有python 3.3.1和mysql 5.0.96(社區)。我安裝MySQL的連接器/蟒,並試圖做使用上的MySQL開發站點樣本代碼的基本連接。這裏是我的簡單的Python腳本:密碼錯誤連接到MySQL數據庫與Python 3.3.1

#!/usr/local/bin/python3 


import sys 
import mysql.connector 

db_config = { 
    'user': 'joebloggs', 
    'password': 'cleartext_passwd', 
    'host': '127.0.0.1', 
    'database': 'mydb' 
} 
cnx = mysql.connector.connect(**db_config) 
cursor = cnx.cursor() 
query = ('select usable_name, user_id from user') 
cursor.execute(query) 
for (usable_name, user_id) in cursor: 
    print("{} is the usable name of {d}".format(usable_name, user_id)) 
cursor.close() 
cnx.close() 

但我正在逐漸連接到數據庫

"Authentication with old (insecure) passwords "\ 
mysql.connector.errors.NotSupportedError: Authentication with old (insecure) passwords is not supported. For more information, lookup Password Hashing in the latest MySQL manual 

什麼我做錯了什麼錯誤?任何幫助非常感謝

回答

2

的MySQL支持兩種密碼加密方案,而你使用的是舊舊版本。較新的客戶拒絕使用這些,因爲它們非常微不足道。

您需要將密碼更新爲新的樣式:http://dev.mysql.com/doc/refman/4.1/en/old-client.html

+1

感謝您的回覆。我找到了答案,這有點模糊(至少對我來說!)。的第一件事,我沒有張貼在這裏計算器之前,一個是更新的mysql用戶表中的密碼,才能使用新風格的密碼。 python腳本仍然無法工作。然後檢查你的鏈接後,我檢查的權限在phpMyAdmin用戶,並將其設置爲已經使用的新密碼,如我所料。 hmmmmm。但最終我所要做的就是「刷新特權」以使用新信息更新mysqld。等瞧,蟒蛇開心!我也快樂!謝謝! – 2013-04-11 08:54:48

+0

對不起,我不能投票,不要有代表呢! – 2013-04-11 08:55:33