Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def write_to_mysql(df):
- """ append all records from a dataframe
- into MySQL table
- """
- df.write.jdbc(
- url='jdbc:mysql://host/db',
- table='mysql_tbl',
- mode='append',
- properties={
- 'user': 'mysql_user',
- 'password': 'mysql_pw',
- 'driver': 'com.mysql.jdbc.Driver'
- }
- )
- def read_from_mysql():
- """ read all records from a MySQL table
- into a dataframe and return
- """
- df = hiveContext.read.format('jdbc') \
- .option('driver', 'com.mysql.jdbc.Driver') \
- .option('url', 'jdbc:mysql://host/db') \
- .option('dbtable', '({query}) as T'.format(query='SELECT * FROM table')) \
- .option('user', 'mysql_user') \
- .option('password', 'mysql_pw') \
- .load()
- return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement