0

This might be a simple one, but I couldn't figure it out. I couldn't connect to the database that I created 'clearview' in mysql through. Please advise. Thanks!

NameError Traceback (most recent call last) in 3 try: ----> 4 connection = mysql.connector.connect(host='localhost', 5 database='clearview',

NameError: name 'mysql' is not defined

1
  • Did you forget the import statement? See this link Commented Jun 15, 2020 at 14:15

4 Answers 4

2

Have you installed the mysql-connector package? Try installing it first with pip install mysql-connector and then import the package import mysql.connector before running your script.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I re-install to all environment, but not sure if I have to do it that way.
0

somewhere on that same file there should be something like this at the top: import mysql.connector ... connection = mysql.connector.connect(host='localhost', 5 database='clearview', ... you should also have the python libraries for mysql installed on your machine. see more -> https://dev.mysql.com/doc/connector-python/en/connector-python-installation.html

1 Comment

I reinstall in every environment I created to make sure it work. Thanks!
0

Which version of python you are using???

a)first check you have import mysql.connector. If it is there and not working then can follow following steps.

b) It may be that mysql is not properly installed .Check via pip search mysql-connector | grep --color mysql-connector-python .

c) Install via : pip install mysql-connector-python-rf Hope it will help.

Comments

0

All comments & suggestions appreciated. I did everything suggested here. And yes, I basically have to install the mysql.connector to every environment I created to be sure. I think perhaps, that's why it indicated that mysql is not defined. Lesson learned>..

As follow up question... is there such thing as installing every Python extensions globally so I would not reinstall it in several environments. never tried it before, as I perhaps tinkering with different environments not knowing which one I'm currently using. :)

Thanks guys!!!

Comments

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.