Agradecemos tu ayuda para difundir nuestros posts referente a las ciencias de la computación.
Ejemplo 1: Python instalar conector mysql
pip3 install mysql-connector-python #Python 3
pip install mysql-connector-python
Ejemplo 2: cómo instalar mysql python
pip install mysql-connector
Ejemplo 3: cómo instalar el conector python de mysql en mac
pip install mysql-connector-python
Ejemplo 4: conector python mysql
# real nice guide, as well as instalation guide: https://pynative.com/python-mysql-database-connection/# pip install mysql-connector-pythonimport mysql.connector
from mysql.connector import Error
try:
connection = mysql.connector.connect(host='localhost',
database='Electronics',
user='pynative',
password='[email protected]#29')if connection.is_connected():
db_Info = connection.get_server_info()print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()print("You're connected to database: ", record)except Error as e:print("Error while connecting to MySQL", e)finally:if(connection.is_connected()):
cursor.close()
connection.close()print("MySQL connection is closed")
Ejemplo 5: conector python mysql
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword")print(mydb)
Ejemplo 6: ejemplo de consulta de conector mysql / python
Press CTRL+C to copy import datetime
import mysql.connector
cnx = mysql.connector.connect(user='scott', database='employees')
cursor = cnx.cursor()
query =("SELECT first_name, last_name, hire_date FROM employees ""WHERE hire_date BETWEEN %s AND %s")
hire_start = datetime.date(1999,1,1)
hire_end = datetime.date(1999,12,31)
cursor.execute(query,(hire_start, hire_end))for(first_name, last_name, hire_date)in cursor:print(", was hired on :%d %b %Y".format(
last_name, first_name, hire_date))
cursor.close()
cnx.close()
Acuérdate de que tienes permiso de agregar una reseña si te ayudó.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)