2015-02-05 77 views
0

我有樹莓派的代碼應該發送傳感器數據到Windows 7的遠程mysql服務器。我已經修改my.cnf文件在樹莓派綁定地址,我也做了如下設置,python遠程數據庫連接

GRANT ALL ON TO'root'@'%'IDENTIFIED by'mumbai';

FLUSH PRIVILEGES;

,我有如下的代碼,

import MySQLdb 
def temp_sensor(): 
    conn = MySQLdb.connect(host = '192.168.1.103', user = 'root', passwd 
     = 'mumbai', db = 'weather', port = 3306) 
      cursor = conn.cursor() 
    while True: 
     try: 
      date = time.strftime("%d/%m/%Y") 
      temp,humidity,light = main.reading() 
      args= ('192.168.1.145', 'b8:27:eb:06:e4:4b', 'Temp_PI', temp) 
      cursor.callproc('SPR_IU_Sensor_Data',args) 
      conn.commit() 
      time.sleep(interval2) 
     except MySQLdb.Error, e: 
      print 'Error %d: %s' % (e.args[0], e.args[1]) 

這給誤差,

Process Process-1: 
    Traceback (most recent call last): 
    File "/usr/lib/python2.7/multiprocessing/process.py", line 258, 
    self.run() 
    File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run 
    self._target(*self._args, **self._kwargs) 
    File "procedure2.py", line 19, in temp_sensor 
    conn = MySQLdb.connect(host = '192.168.1.103', user = 'root', 
    passwd = 'mumbai', db = 'weather', port = 3306) 
    File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 
    81, in Connect 
    return Connection(*args, **kwargs) 
    File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 
    187, in __init__ 
     super(Connection, self).__init__(*args, **kwargs2) 
     OperationalError: (1130, "Host '192.168.1.145' is not allowed to 
     connect to this MySQL server") 

回答

0

他們需要給予在windows的MySQL服務器的權限7