buzzybee
buzzybee

Reputation: 11

Failing to create MQSQL database in python (cursor = db.cursor() not working) - Newbie Question

Following a tutorial video to learn how to make my first database as follows:

import mysql.connector
db = mysql.connector.connect()
host="localhost"
user="root"
passwd="xxxxxxxx"

However when i use the following (>>> cursor = db.cursor(), this error msg shows up... not sure what has happened as i don't understand anything yet.)

cursor = db.cursor()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\asans\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mysql\connector\connection.py", line 809, in cursor
    raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.

I'm following the 1st video in a series of tutprials by 'Tech with Tim' on youtube. Also checked https://www.datacamp.com/community/tutorials/mysql-python#CD and that website seems to use the same command with no issues :(

Any ideas?

I'm using python 3.8.4 btw

Upvotes: 1

Views: 88

Answers (1)

nbk
nbk

Reputation: 49373

You have to put the data in the parenthesis and seperate them with commas like below

import mysql.connector
db = mysql.connector.connect(
    host= 'localhost',
    user='root',
    passwd='xxxxxxxx')
mycursor = db.cursor()

Upvotes: 1

Related Questions