MySQL Forums
Forum List  »  Connector/Python

Sytax error
Posted by: Mikail Baum
Date: December 12, 2020 11:52AM

## Hello, I got an error on line 11 when I run this:

import mysql.connector

try:
conn = mysql.connector.connect\
(host='localhost',
database='newbase',
user='root',
password='pwwwwwww#')

#Creating a cursor object using the cursor() method
cursor = conn.cursor() ########## this causes trouble #############

#Dropping EMPLOYEE table if already exists.
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")

#Creating table as per requirement
sql ='''CREATE TABLE EMPLOYEE(
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INT,
SEX CHAR(1),
INCOME FLOAT
)'''
cursor.execute(sql)

#Closing the connection
conn.close()

######################################## on Console :
File "/home/charger/PycharmProjects/neu1/testmy.py", line 11
cursor = conn.cursor()
^
SyntaxError: invalid syntax

Process finished with exit code 1
##########################################
who can help me please?

Options: ReplyQuote


Subject
Written By
Posted
Sytax error
December 12, 2020 11:52AM
December 12, 2020 02:33PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.