cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Can we use spark-stream to read/write data from mysql? I can't find an example.

sarvesh
Contributor III

If someone can link me an example where stream is used to read or write to mysql please do.

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

Regarding writing (sink) is possible without problem via foreachBatch .

I use it in production - stream autoload csvs from data lake and writing foreachBatch to SQL (inside foreachBatch function you have temporary dataframe with records and just use write to any jdbc or odbc).

Here is more deltails:

https://docs.databricks.com/spark/latest/structured-streaming/foreach.html

Reading stream from mysql is not the best architecture and officialy is not possible. Theoretically you could create custom reciver but better idea is just put what you save to mysql to kafka or some other broker/queue.

Easy way around (but it make sense only if you have less new records than 1 per second) is to use Azure logic apps - new record in Mysql is trigger and append data to Event hub which is then read as a stream by Databricks.

View solution in original post

3 REPLIES 3

Thank you for taking sometime out to reply, as of now i have not found a structured way.

Hubert-Dudek
Esteemed Contributor III

Regarding writing (sink) is possible without problem via foreachBatch .

I use it in production - stream autoload csvs from data lake and writing foreachBatch to SQL (inside foreachBatch function you have temporary dataframe with records and just use write to any jdbc or odbc).

Here is more deltails:

https://docs.databricks.com/spark/latest/structured-streaming/foreach.html

Reading stream from mysql is not the best architecture and officialy is not possible. Theoretically you could create custom reciver but better idea is just put what you save to mysql to kafka or some other broker/queue.

Easy way around (but it make sense only if you have less new records than 1 per second) is to use Azure logic apps - new record in Mysql is trigger and append data to Event hub which is then read as a stream by Databricks.

Great example of your use case @Hubert Dudekโ€‹ 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group