mysql-connector

name 'mydb' is not defined

name 'mydb' is not defined Question: I’d like to access mydb variable on line 15, but it can¨t be seen. Even though I would go for Global variable, it still stays the same. Code: import mysql.connector def connect(): try: mydb = mysql.connector.connect( host=’localhost’, user=’root’, password=’12345′, database="Food" ) except: print("Possibly wrong PWD") mycursor = mydb.cursor() Error: …

Total answers: 1

Connect to cloudSQL db using service account with pymysql or mysql.connector

Connect to cloudSQL db using service account with pymysql or mysql.connector Question: I have a running CloudSQL instance running in another VPC and a nginx proxy to allow cross-vpc access. I can access the db using a built-in user. But how can I access the DB using a Google Service Account? import google.auth import google.auth.transport.requests …

Total answers: 3

Querying data with common words using python connector — avoid code duplication

Querying data with common words using python connector — avoid code duplication Question: I am new to SQL and relatively new to python. I’m trying to fetch some information from the database using mysql.connector. And I found myself copying and pasting a lot. I tried using LIKE so that I could just execute once and …

Total answers: 1

Login method using MySql.connector not working properly

Login method using MySql.connector not working properly Question: I created a a method in pythin so that user could login as a user or as an admin but the program is not working as I expected it to be, I am posting the whole program, but mainly the error is coming in login method as …

Total answers: 1

i cant use python input to create mysql database

i cant use python input to create mysql database Question: I want to take input from user of creating a mysql database I cant use python input to create mysql databasewhat i tryed Getting this error please help the error Asked By: NAKULOP1 || Source Answers: execute() method parameters must be provided as a tuple, …

Total answers: 2

NameError: name 'dishID' is not defined. Did you mean: 'dishid'?

NameError: name 'dishID' is not defined. Did you mean: 'dishid'? Question: this is the code of the following function Function: def dishID(): query = ‘select count(*), max(DishID) from Dish’ cur.execute(query) fetch = cur.fetchall() for i in fetch: if i[0] == 0: return 1 else: return (int(i[1]) + 1) Error code dishname = input(‘Enter Dish Name: …

Total answers: 1

Python MySql Connector Not enough parameters for the SQL statement

Python MySql Connector Not enough parameters for the SQL statement Question: Can’t Insert Values into MySql Database Using This Piece Of Code: def CreateUser(Name, Password, Email, Version): global user print(Password) user = [tuple(Name), tuple(Email), tuple(Password), tuple("User"), tuple("0"), tuple(Version)] my_cursor.executemany(f"INSERT INTO users (usersUid, usersEmail, usersPwd, UsersPerms, usersMoney, gameVersion) VALUES (%s, %s, %s, %s, %s, %s)", user) …

Total answers: 1

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax;

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; Question: mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Name, Roll Number, Email, Department, Biography, Insta_handle, Facebook_handle, ‘ at line 1 I am trying …

Total answers: 1

MySQL Python connector error while inserting

MySQL Python connector error while inserting Question: So I am trying to build a database in MySQL using python. I already created the database and created the table I want to use. it’s called ‘alliances‘. Now this table only has two columns, an ID column and a alliance_name column. The ID’s auto increment , and …

Total answers: 1

INSERT table names using SELECT statement in MySQL

INSERT table names using SELECT statement in MySQL Question: In MySQL, I know I can list the tables in a database with: SHOW TABLES But I want to insert a table name into a specified table, for example: INSERT INTO dataset_names (dataset) SELECT table_name FROM information_schema.tables WHERE table_schema = ‘%s’; But when I execute the …

Total answers: 3