Error
ProgrammingError: 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides
When
While inserting bulk CSV data in the Mysql table using python.
<pre><code class="html">
import mysql.connector as mysql
import csv
def connect(db_name):
try:
return mysql.connect(user='root',password='anish@123',host='localhost',database=db_name)
except Error as e:
print(e)
if __name__=='__main__':
connection=connect('sales')
cursor=connection.cursor()
cursor.execute("drop table if exists salesperson")
cursor.execute('''create table salesperson(
id int(10) not null auto_increment,
Country varchar(100),
Item_Type varchar(100),
Order_Date varchar(100),
Units_Sold int(10),
Unit_Cost int(10),
primary key (id)
)''')
q='''load data local infile
'F:\Linkedin\100_Sales_Records.csv'
into table salesperson fields terminated by ',' enclosed by '"' (Country,Item_Type,Order_Date,Units_Sold,Unit_Cost);'''
cursor.execute(q)
connection.commit()
cursor.execute('select * from salesperson limit 10')
print(cursor.fetchall())
connection.close()
</code></pre>
Solution
1>Add 1 more parameter allow_local_infile=True in mysql.connect function
mysql.connect(user='root',password='anish@123',host='localhost',database=db_name,allow_local_infile=True)
2>Set global local_infile=1;
0 Comments