2

I have matlab data table T in my matlab with more than 40,000 rows. I want to insert this table into MySQL database. This table T has columns with different data types(char, date, integer). I tried following:

fastinsert(conn,'tablename',colnames2,T)

I even tried with "Insert" and datainsert". I converted table to cellarray, but still it didn't work. Then I tried to convert that cellarray into mat, but i couldn't convert it to matrix It says all the content should be of same data type to convert it into matrix.

Is there any way i can insert my data table present in matlab to MySQL database?

1 Answer 1

2

Instead of converting your data from a cell array to a matrix have you tried converting it to a table using cell2table() and then using insert(). There is an example in the MATLAB documentation that can be found here.

The linked example uses multiple data types in a cell and then converts them to a table (instead of a matrix) which can then be written to the database with mixed data types.

Sign up to request clarification or add additional context in comments.

2 Comments

HI Bern, i did try it. I created a data table in matlab with multiple records in it. But couldn't pass that table into my database. I found an alternate solution to it . It seems matlab cannot send table with multiple records into database. So I run a for loop and each iteration created a table with just one row each time and only that row was inserted into my table in database. But this process took more than 1.5 hours to complete for just 40,000 rows. I was wondering if I can pass the data from matlab into database without using for loop.
@learnmathematica have you tried using the method of writing each table to a data file and then using bulk insert as is recommended by Mathworks for large data sets? here is the link for the example from mathworks on writing large data sets (multiple tables) efficiently to databases

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.