Search
 
SCRIPT & CODE EXAMPLE
 

SQL

python how to connect to sql server

import pandas as pd
import pyodbc 

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=RONSQLEXPRESS;'
                      'Database=test_database;'
                      'Trusted_Connection=yes;')

df = pd.read_sql_query('SELECT * FROM products', conn)

print(df)
print(type(df))
Comment

how to connect sql database in python

#create database in python with mysql

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")
Comment

python connection to remote SQL server

import pyodbc
cnxn = pyodbc.connect(DRIVER='{SQL Server}',SERVER='***server ip address**',DATABASE='**cataloguename**',UID='**myusername**',PWD='**mypassword**')
cursor = cnxn.cursor()
Comment

connect to sql database python

import sqlite3

try:
    sqliteConnection = sqlite3.connect('test.db')
    cursor = sqliteConnection.cursor()
    print("SQLITE Connection Established!")
    cursor.close()

except sqlite3.Error as error:
    print("Error while connecting to sqlite", error)
finally:
    if (sqliteConnection):
        sqliteConnection.close()
        print("Connection closed")
Comment

sql server in python

# C:UsersYour NameAppDataLocalProgramsPythonPython36-32Scripts>python -m pip install mysql-connector-python
# Or you can refer the page: https://thietkewebhcm.com.vn/ket-noi-python-voi-sql-server/
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql like 
Sql :: xampp mysql command to import a large database 
Sql :: postgres select except 
Sql :: list mysql tables and views 
Sql :: mysql generate create table script 
Sql :: open postgresql.conf in centos 
Sql :: select only distinct values from another table and excluding from current table 
Sql :: get month sql 
Sql :: sql or 
Sql :: minus equivalent in my sql 
Sql :: Select All From A Table In A MySQL Database 
Sql :: spark apache sql coalesce 
Sql :: TRIGGER AFTER 
Sql :: oracle last connection 
Sql :: create postgres role and database for bitbucket 
Sql :: mysql grouping functions 
Sql :: no suitable driver found for sqlite 
Sql :: postgres add prefix to primary key 
Sql :: sql cte example 
Sql :: how to check current root password in mysql 
Sql :: cascade syntax in sql 
Sql :: oracle synonym procedure 
Sql :: update query in sql 
Sql :: sql server inner join 
Sql :: soql- select all fields 
Sql :: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails 
Sql :: what is postgresql 
Sql :: find duplicates in column sql 
Sql :: create user in mysql 
Sql :: sql xor 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =