1

I am trying to interact directly with data from a MySQL database in ArcMap using Python. So far, I have successfully connected the database using the MySQLdb.connect() function and have successfully executed queries using the cur.execute() function. I also am able to print the results in the Python window.

I cannot, however, figure out how to create a table from the query output that I can then use to, for instance, join to a shapefile or display XY data. I assumed that the MakeQueryTable_management() function would allow me to do this, but the syntax is very confusing to me. Do I execute the query using cur.execute() and then execute this function, does this function replace the cur.execute() function, or do I do something altogether different?

for example, here is a query:

cur.execute("SELECT count(zip_codes.zip_code) AS Zips, zip_codes.state FROM   zip_codes GROUP BY zip_codes.state ORDER BY zip_codes.state ASC")

so how would I write the MakQueryTable_management() function given this syntax?

MakeQueryTable_management (in_table, out_table, in_key_field_option, {in_key_field}, {in_field}, {where_clause})

I am new to ArcPy.

  • Welcome to GIS SE! As a new user be sure to take the Tour where you will see that we try to keep chit chat (e.g. greetings, thanks, signatures, etc) out of questions and answers (think of them as being a wiki). For help with code we need you to include a code snippet of what you have tried and where you are stuck. – PolyGeo Nov 30 '15 at 21:31
  • Please edit the question to specify the exact version of ArcGIS in use, as well as the exact Python code. I suspect you're trying to use two different access libraries that do not work together, and are being too casual in object access methods. – Vince Nov 30 '15 at 21:46
  • Please do not re-insert the "chit-chat" that has been removed by policy. – Vince Dec 1 '15 at 0:10
1

Consulting the online documentation for Make Query Table, it states:

This tool accepts data from an ArcSDE geodatabase, a file geodatabase, a personal geodatabase, or an OLE DB connection.

So your first task is to create an OLE DB connection to MySQL (since MySQL isn't supported in enterprise geodatabases).

I'd recommend making a view in MySQL and just accessing that through OLE DB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.