The Problem:
I want to read data from an xls file into MySQL database using python, I am new to MySQL, I have my database ic4projournal
and the table ic4projournal
too, the table contained up to 30 columns.
EDIT:
This what I get after running the select query:
Anytime I run this query:
SHOW GRANTS FOR root
I get this error:
Error Code: 1141. There is no such grant defined for user 'root' on host '%'
mysql version: 8.0.29
My Solution:
import pymysql
import xlrd
HOST = 'localhost'
PORT = 3306
USER = "root"
PASSWORD = "password"
DB = 'ic4projournal'
book = xlrd.open_workbook('ic4projournal.xls')
sh = book.sheet_by_index(0)
# Connect to database
connection = pymysql.connect(host=HOST,
user=USER,
password=PASSWORD,
db=DB,
port=PORT,
autocommit=True)
cursor = connection.cursor()
# Insert in to already created database in mysql
query = """INSERT INTO ic4projournal transid,
branchid,
branchcode,
currentdate,
postingdatestamp,
psdate,
postingdate,
posteddate,
postedtime,
intpostingdates,
postingtime,
postingdates,
accountno,
accountid,
accountdesc,
amount,
currcode,
transitcode,
transcode,
transtype,
transtypeid,
translocation,
prodcode,
narrative,
branchadded,
depositorname,
addedby,
addedapprovedby,
workstationipadded,
transmode,
transtime VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
# loop over each row
# Resolving values to insert
for row in range(1, sh.nrows):
values = [sh.cell_value(row, col) for col in range(sh.ncols)]
# write pair to db
cursor.execute(query, *values)
# close everything
cursor.close()
connection.close()
The error:
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
My question: How do I resolve this error?
Thank you