0% found this document useful (0 votes)
3 views4 pages

Python 10

The document is a Jupyter Notebook containing Python code for connecting to a MySQL database using the mysql-connector-python library. It includes operations such as creating a database, creating a table, inserting values into the table, and displaying the values. The notebook also encounters a connection error while trying to install the MySQL connector package.

Uploaded by

Diguu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Python 10

The document is a Jupyter Notebook containing Python code for connecting to a MySQL database using the mysql-connector-python library. It includes operations such as creating a database, creating a table, inserting values into the table, and displaying the values. The notebook also encounters a connection error while trying to install the MySQL connector package.

Uploaded by

Diguu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10_exp10 - Jupyter Notebook

In [1]:

conda install -c anaconda mysql-connector-python

Collecting package metadata (current_repodata.json): ...working... failed

Note: you may need to restart the kernel to use updated packages.

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <[Link]


rg/anaconda/win-64/current_repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.


HTTP errors are often intermittent, and a simple retry will get you on your
way.
'[Link]

In [2]:

import [Link]

#Create the connection object


myconn = [Link](host = "localhost", user = "root",passwd = "root")

#creating the cursor object


cur = [Link]()

try:
dbs = [Link]("show databases")

except:
[Link]()
for x in cur:
print(x)
[Link]()

('information_schema',)
('mysql',)
('performance_schema',)
('sys',)

localhost:8888/notebooks/10_exp10.ipynb 1/4
10_exp10 - Jupyter Notebook

In [8]:
# Program to create Database

import [Link]

#Create the connection object


myconn = [Link](host = "localhost", user = "root",passwd = "root")

#creating the cursor object


cur = [Link]()

try:
[Link]("CREATE DATABASE mydatabase")

except:
[Link]()
for x in cur:
print(x)
[Link]()

In [20]:

# Program to show Database

#Create the connection object


myconn = [Link](host = "localhost", user = "root",passwd = "root")

#creating the cursor object


cur = [Link]()

try:
dbs = [Link]("show databases")

except:
[Link]()
for x in cur:
print(x)
[Link]()

('information_schema',)
('mydatabase',)
('mysql',)
('performance_schema',)
('sys',)

In [21]:
#Program to create table

import [Link]

myconn = [Link](host = "localhost", user = "root",passwd = "root", databas

#creating the cursor object


cur = [Link]()

[Link]("CREATE TABLE EMP(FN CHAR(20),LN CHAR(20),AGE INT")

localhost:8888/notebooks/10_exp10.ipynb 2/4
11/24/22, 9:27 AM 10_exp10 - Jupyter Notebook

In [23]:
#Program to show table

import [Link]

myconn = [Link](host = "localhost", user = "root",passwd = "root", databas

#creating the cursor object


cur = [Link]()

[Link]("SHOW TABLES")

for x in cur:
print(x)

('emp',)

In [30]:

#Insert Values

import [Link]

myconn = [Link](host = "localhost", user = "root",passwd = "root", databas

#creating the cursor object


cur = [Link]()

sql="INSERT INTO EMP(FN,LN,AGE)VALUES(%s,%s,%s)"


val=('digvijay','patil','50')

[Link](sql,val)

[Link]();

In [32]:
#Insert Values
import [Link]

myconn = [Link](host = "localhost", user = "root",passwd = "root", databas

#creating the cursor object


cur = [Link]()

sql="INSERT INTO EMP(FN,LN,AGE)VALUES(%s,%s,%s)"


val=('raj','patil','19')

[Link](sql,val)

[Link]();

localhost:8888/notebooks/10_exp10.ipynb 3/4
11/24/22, 9:27 AM 10_exp10 - Jupyter Notebook

In [34]:

#Insert Values
import [Link]

myconn = [Link](host = "localhost", user = "root",passwd = "root", databas

#creating the cursor object


cur = [Link]()

sql="INSERT INTO EMP(FN,LN,AGE)VALUES(%s,%s,%s)"


val=('Yash','hadai','22')

[Link](sql,val)

[Link]();

In [34]:

# Display Values

import [Link]

myconn = [Link](host = "localhost", user = "root",passwd = "root", databas

cur = [Link]()

[Link]("SELECT * FROM EMP")

result= [Link]()

for x in result:
print(x)
print("\n")

('digvijay', 'patil', 50)

('raj', 'patil', 19)

('Yash', 'hadai', 22)

In [ ]:

localhost:8888/notebooks/10_exp10.ipynb 4/4

You might also like