MySQL error in python

Hi everyone , I had this error that came while using MySQL in python. Can anyone please help me in it

@SyedBilalHasan you want to connect your sql database to rasa to fetch the data or execute query? can you share rasa version rasa --version ?

It seems that the database you’re trying to connect to does not exist. In terminal open mysql and check whether this database exists or not by running the command show database; Mark this as solution if this works for you

1 Like

@SyedBilalHasan Just a demo code for your ref Syed I know you will solve this by your own :slight_smile:

@SyedBilalHasan Do create the scheme for your database first i.e tables with the database name test database

import mysql.connector
def DataUpdate(FirstName,LastName,Feedback): 
              mydb = mysql.connector.connect( host="localhost", user="root",  
               passwd="root", database="Rasa_feedback") 
               mycursor = mydb.cursor() 
               sql='INSERT INTO FeedBack_rasa_date (firstName, lastName, feedback) VALUES ("{0}","{1}", "{2}");'.format(FirstName,LastName,Feedback) 
                mycursor.execute(sql) 
                mydb.commit()

one package needs to be installed which can be installed with the given command

pip install mysql-connector-python-rf

Good Luck!

1 Like

In your code, you are trying to connect to a database (lines 2-7) before creating it (line 9).

Create the database in a terminal first. Then no need for lines 9 and 10.

Keep in mind that this is not a Rasa-related question, maybe consider StackOverflow for more general questions :slight_smile:

1 Like