1

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

1
  • Surprising that the connect line does not err out having no parameters! Commented Jul 19, 2020 at 23:12

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

3 Comments

Ok, this way shows there is a refusal of access by my machine and states the port number. Is there something else i need to start up before doing this? File "C:\Users\asans\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mysql\connector\network.py", line 511, in open_connection raise errors.InterfaceError( mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it)
No that is copied directly from my VS code, but of course you need a mysql server running at the local computer. there should be a service named mysql be running at your machine. that said did you install mysql server at your computer?
Yes I did download it all. I checked on my control panel>uninstall programmes that mysql server was installed - perhaps there was an issue. I didn't check to see if there was a mysql service running on task manager though before deleting it all. I'll download again, give it a go and be sure to check the service is running this time. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.