命令行的MySQL按預期方式工作:如何在MAMP中使用mysql-connector-python?
mysql --host=localhost --user=django3 --password=django3 \
--database=django3 --port=8889
生產:
...
Server version: 5.5.34 Source distribution
...
但下面的腳本(改編自MySQL的連接器,蟒== 1.2.3網站)生產:
2003: Can't connect to MySQL server on 'localhost:8889' \
(61 Connection refused)
爲什麼這應該是?
import mysql.connector
from mysql.connector import errorcode
try:
cnx = mysql.connector.connect(user='django3', password='django3',
host='localhost', port='8889',
database='django3')
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exists")
else:
print(err)
else:
cnx.close()
注
使用局域網上,但不嘗試使用本地MAMP MySQL服務器時,MySQL服務器此腳本將工作。因此,只要我有這個問題,發展環境不是那麼便攜!