0

I'm still new to python linked to MySQL, and I'm getting a problem like below. are there any clues I should do? Here is my code:

import mysql.connector 
from netCDF4 import Dataset 
import numpy as np 
import matplotlib.pyplot as plt 
import cartopy.crs as ccrs 
import pyodbc
 
file = '182.16.248.173:8080/dods/INA-NWP/2021030100/2021030100-d02-asim' 
url = Dataset(file) rainc = url.variables['rainc'][7,0,:,:] 

con = mysql.connector.connect( host = "", user = "", password = "", db = "" ) 

dbcursor = con.cursor() 

sql = "INSERT INTO gis (id, name, var1) VALUES (%s, %s, %s)"
data = ("01", "2021030100", rainc) 
dbcursor.execute(sql, data) 
con.commit()
 
print("records inserted") 
j__carlson
  • 1,346
  • 3
  • 12
  • 20
  • Kindly paste the code here –  Aug 20 '21 at 04:12
  • import mysql.connector from netCDF4 import Dataset import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs import pyodbc file = 'http://182.16.248.173:8080/dods/INA-NWP/2021030100/2021030100-d02-asim' url = Dataset(file) rainc = url.variables['rainc'][7,0,:,:] con = mysql.connector.connect( host = "", user = "", password = "", db = "" ) dbcursor = con.cursor() sql = "INSERT INTO gis (id, name, var1) VALUES (%s, %s, %s)" data = ("01", "2021030100", rainc) dbcursor.execute(sql, data) con.commit() print("records inserted") – user16710611 Aug 20 '21 at 04:14
  • Please [edit] the question and paste the code –  Aug 20 '21 at 04:14
  • @Sujay I've edited it – user16710611 Aug 20 '21 at 04:42
  • What is the error? – gshpychka Aug 20 '21 at 06:35

1 Answers1

0

MySQL doesn't accept arrays at all masked or otherwise. The error is simply reading back to you the data type you are sending, in this case a maskedarray in the form of rainc, and telling you that there is no equivalent MySQL data type, or that where you are sending it doesn't accept that data type.

This documentation about MySQL data types should clear it up:

https://dev.mysql.com/doc/refman/8.0/en/data-types.html

j__carlson
  • 1,346
  • 3
  • 12
  • 20
  • what data type do you think I should use for the data coming from here (182.16.248.173:8080/dods/INA-NWP/2021030100/2021030100-d02-asim) ? because I have tried several data types but still not working – user16710611 Aug 20 '21 at 04:41
  • That all depends. Is this data being stored to be used by python at a later date or is it going to be pulled and displayed by JavaScript, ect. If you will only be using it in python you can pickle it and store it that way. If this is intended to be used as JavaScript you will likely want to convert it to JSON with python and then save it as a `VARCHAR`. For other applications you may have to break it up and store it in pieces. – j__carlson Aug 20 '21 at 12:07