mysql-connector

Cut strings separated by comma in python

Cut strings separated by comma in python Question: I want to read my sql database values and assign them in to variables which I will be using for further processing. import mysql.connector mydb = mysql.connector.connect( host=’x.x.x.x’, user="admin", password="secret", database="dbname" ) mycursor = mydb.cursor() mycursor.execute("SELECT * FROM dbname.bb_users") myresult = mycursor.fetchall() for x in myresult: print(x) …

Total answers: 2

Configuring MySQL database inside Flask factory function without SQLAlchemy

Configuring MySQL database inside Flask factory function without SQLAlchemy Question: I am new to Flask and trying to build a simple application with a MySQL database. However, I prefer not to use SQLAlchemy. Instead, I would like to use mysql.connector and direct SQL statements to SELECT, INSERT, UPDATE or DELETE from the database. I have …

Total answers: 1

AttributeError: 'NoneType' object has no attribute 'fetchall'

AttributeError: 'NoneType' object has no attribute 'fetchall' Question: I tried to return the result of an SQL query. This works perfectly with pyodbc but not with mysql-connector. Error Output File "/mySQLDB.py", line 17, in execute_and_fetch result = conn.cursor().execute(query, params).fetchall() AttributeError: ‘NoneType’ object has no attribute ‘fetchall’ Code import mysql.connector class MYSQLDB: def __init__(self): self.host = …

Total answers: 2

Lost connection between Python program and MySQL

Lost connection between Python program and MySQL Question: Why do I get this error? Mysql.connector.errors.DatabaseError: 2003 (HY000): Can’t connect to MySQL server n ‘3.XX.XXX.89’ (110) I am collecting data from MQTT broker and storing it in a MySQL database. For subscribing to the topics on MQTT broker, I am using Paho MQTT client and for …

Total answers: 1

What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?

What's the difference between MySQLdb, mysqlclient and MySQL connector/Python? Question: So I’ve been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy. There’s MySQLdb There’s mysqlclient And then there’s a mysql connector python What’s each of them, the …

Total answers: 5

How to create a mysql connection pool or any better way to initialize the multiple databases?

How to create a mysql connection pool or any better way to initialize the multiple databases? Question: In my code I am opening two mysql connections and using HTTP requests to insert data into database g.db = mysql.connector.connect(user=a ,password=password, host=localhost,database=mysq1) g.db1 = mysql.connector.connect(user=b,password=password, host=localhost,database=mysql2) @app.route(‘/user/<db>’) def insert(db): #code for inserting data into mysql1 database #code …

Total answers: 3

Writing to MySQL database with pandas using SQLAlchemy, to_sql

Writing to MySQL database with pandas using SQLAlchemy, to_sql Question: trying to write pandas dataframe to MySQL table using to_sql. Previously been using flavor=’mysql’, however it will be depreciated in the future and wanted to start the transition to using SQLAlchemy engine. sample code: import pandas as pd import mysql.connector from sqlalchemy import create_engine engine …

Total answers: 4

mysql-connector python 'IN' operator stored as list

mysql-connector python 'IN' operator stored as list Question: I am using mysql-connector with python and have a query like this: SELECT avg(downloadtime) FROM tb_npp where date(date) between %s and %s and host like %s”,(s_date,e_date,”%” + dc + “%”) NOw, if my variable ‘dc’ is a list like this: dc = [‘sjc’,’iad’,’las’] Then I have a …

Total answers: 3