Python MySQL Create Database In Hindi

Python MySql

Python MySQL Create Database In Hindi – Is Post Me Ham Database Ko Create Karne Wale Hai, And Database Me Kiya Kiya Input Dene Hote Hai, Ye Bhi Dekhne Wale Hai |

ALso Read – MySQL Get Started

Python MySQL Create Database In Hindi

Ab Ham Is Part Me Database Ko Create Karne Wale Hai, Lekin Database Ko Create Karne Ke Se Pahle Hamne Database Se Connection Bana Hota Hai,

Create Connection

DataBase Se Connection Bana Ke Liye Hamne 3 Yani HOST , USER, PASSWORD , Ki Jarurat Hoti Hai, Chaliye Connection Create Karte Hai |

import mysql.connector

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

Aap Code Me Dekh Sakte Hai, Hamne Connction Create Kar Liya Hai, Waise Aap user and password Ko Change kar Sakte Hai |

Ab Ham Database Create Karte Hai, Database Ko Create Karne Ke Liye CREATE DATABASE Commands Ka Istemal Kiya Jata Hai |

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")

Upper Hamne mydb Name Se Connection Banaya Tha, Lekin Yaha Par Hamne Connection Ko Call Kiya Hai, mydb.cursor() Ki Help Se Or mycursor Variable me Connection Le Liya Hai, Ab mycursor Se Commands Ko Execute Kar Sakte Hai, Fir Hamne Line 3 Me Ek Database Ko Create Kiya mydatabase Name se |

Python MySQL Tutorial In Hindi

Ab Hamara Database Create Ho Gaya Hai, Aap Ise Run Karke Check Kar Sakte Hai |

Check if Database Exists

Agar Aapko Ye Check Karna Hai Ki Aapka Pahle Koi Database Create Hai Ya NHi To Niche Diye Code Ko Dekh Sakte Hai Or Ye Check Kar Sakte Hai, Ki Hamara Database Pahle Create Hai, Ya Nhi |

import mysql.connector

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

mycursor = mydb.cursor()

mycursor.execute("SHOW DATABASES")

for x in mycursor:
  print(x)

Output:

('mydatabase',)

Aap Dekh Sakte Hai, Ki Hamne upper Ek Data Base Create Kiya Tha, Wo Hamara WO Output Me Print Ho Gaya Hai |

Leave a Reply

Your email address will not be published. Required fields are marked *