Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

connecting to mysql database using python

import mysql.connector
from mysql.connector import Error

try:
    connection = mysql.connector.connect(host='localhost',
                                         database='Electronics',
                                         user='pynative',
                                         password='pynative@#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")
Comment

connecting python with database

import mysql.connector
from mysql.connector import Error
try:
    connection = mysql.connector.connect(host='localhost',
                                         database='techshop',
                                         user='root',
                                         password=' ')
    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")
Comment

how to connect database in python

import mysql.connector
from mysql.connector import Error

try:
    connection = mysql.connector.connect(host='localhost',
                                         database='Electronics',
                                         user='pynative',
                                         password='pynative@#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")
Comment

database with python connection

#connect to sqlite database in python

import sqlite3

connection = sqlite3.connect("survey.db")
cursor = connection.cursor()
cursor.execute("SELECT Site.lat, Site.long FROM Site;")
results = cursor.fetchall()
for r in results:
    print(r)
cursor.close()
connection.close()
Comment

PREVIOUS NEXT
Code Example
Python :: insert into string python 
Python :: draw bipartite graph networkx 
Python :: Python Pandas - How to write in a specific column in an Excel Sheet 
Python :: python module has no attribute 
Python :: extracting values in pandas 
Python :: inheritance in python 3 example 
Python :: www.pd.date_range 
Python :: examples of function in python 
Python :: primes python 
Python :: how to remove text from plot in python 
Python :: length of series pandas 
Python :: how to create fastapi 
Python :: python raise filenotfounderror 
Python :: python numpy array subtract 
Python :: how to print text in python 
Python :: pandas filter rows by column value regex 
Python :: one-hot encode categorical variables standardize numerical variables 
Python :: how to generate python code 
Python :: python if in list 
Python :: strip plot (normal) 
Python :: python message 
Python :: python - merge and incluse only specific columns 
Python :: df loc 
Python :: como instalar python en ubuntu 20.04 
Python :: get_permissions 
Python :: How to clone or copy a list in python 
Python :: palindrome of a number in python 
Python :: when to use finally python 
Python :: Converting 12 hour clock time to 24 hour clock time 
Python :: pytest monkeypatch 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =