I am trying to insert records into a table MySql
. The table contains id
, and name
as columns.
I do as shown below in the shell pyspark
.
name = 'tester_1'
id = '103'
import pandas as pd
l = [id,name]
df = pd.DataFrame([l])
df.write.format('jdbc').options(
url='jdbc:mysql://localhost/database_name',
driver='com.mysql.jdbc.Driver',
dbtable='DestinationTableName',
user='your_user_name',
password='your_password').mode('append').save()
I get an error below the attribute
AttributeError: 'DataFrame' object has no attribute 'write'
What am I doing wrong? What is the correct way to insert records into a table MySql
frompyspark
source
share