錯誤一:
| 代碼如下 |
複製代碼 |
|
File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)") |
解決方案:
1、編輯my.cnf,預設為/etc/mydql/my.cnf,注釋掉bind-address = 127.0.0.1或者修改為0.0.0.0;
| 代碼如下 |
複製代碼 |
|
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.12、重啟mysql:
sudo /etc/init.d/mysql restart |
錯誤二:
| 代碼如下 |
複製代碼 |
|
File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1130, "Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server") |
解決方案:
| 代碼如下 |
複製代碼 |
|
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;該語句意思為:允許所有用root使用者並且輸入root密碼的主機登入該mysql Server。 |
使用者名稱和密碼替換為需要的,如果將'%'換成相應主機名稱那麼只有該主機可以登陸。
錯誤三:
| 代碼如下 |
複製代碼 |
|
(1040, 'Too many connections')
The reason is: 'NoneType' object has no attribute 'cursor'網路爬蟲改為多線程後,串連資料庫出現以上錯誤。 |
解決方案一:
| 代碼如下 |
複製代碼 |
|
編輯my.cnf,預設為/etc/mydql/my.cnf,修改max_connections的值為10000,預設為100,實際MySQL伺服器允許的最大串連數16384。 |
解決方案二:
使用資料庫連接池。
解決方案三:
之前的程式結構為抓取到一條資料即產生一條sql語句即插入一條資料,修改程式結構為將各進程線程產生的sql語句put進Queue,用一個單獨的進程不斷get出sql插入資料庫。