Good Afternoon, I wrote a query in MySQL, and I want to execute the same query in Python. The Code I wrote as Follows. 1.
import mysql.connector
from mysql.connector import Error
try:
connection = mysql.connector.connect(host='localhost',
database='AdventureWorks2012',
user='root',
password='r@#*****')
sql_select_Query = "select * from Person.person"
cursor = connection.cursor()
cursor.execute(sql_select_Query)
records = cursor.fetchall()
However, I'm getting following error message while running part two- ''File "", line 5 password='r@#*****') ^ SyntaxError: unexpected EOF while parsing''
Any suggestion please how to overcome this problem?
You are missing the except
clause:
try:
connection = mysql.connector.connect(host='localhost',
database='AdventureWorks2012',
user='root',
password='r@#*****')
except Exception as e:
print(e)
You should check the documentation
for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.