I have a .sql script that contain all mysql queries. Now suppose after executing the script I want to check if the queries run successfully or not. In command line if we do
echo $?
Then it will return 0 if query is success and 1 if its not successful.
No I want to do it in python Script. How can this be done ?
My python script :
import mysql.connector
from mysql.connector import errorcode
try:
    cnx = mysql.connector.connect(user='myuser', password='mypass', host='127.1.2.3', database='mydb')
except mysql.connector.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print("Something is wrong with your user name or password")
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print("Database does not exist")
    else:
        print(err)
else:
    cursor = cnx.cursor()
    cursor.executescript("sql_queries.sql")
    cnx.close()
 
     
    