Create Database
Posted 2022-11-07 09:44:40
0
234
To create a database in MySQL, use the "CREATE DATABASE" statement:
Below is the example of Creating a MySQL Database in Python:
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword" ) mycursor = mydb.cursor() mycursor.execute("CREATE DATABASE mydatabase")
If the above code was executed with no errors, It means your database has been successfully created.
Check if Database Exists
You can also check if a database exist before you create a database by listing all databases in your system by using the "SHOW DATABASES" statement. Below is the example:
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)
Search
Categories
- Information Technology
- Office Equipment and Supplies
- Cars and Trucks
- Persons
- Books and Authors
- Tutorials
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Games
- Gardening
- Health
- Home
- Literature
- Music
- Networking
- Other
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Read More
Europe Powder Sulfur Market Impact, Potential, Market Flow, Developments and Analysis
Executive Summary Europe Powder Sulfur Market :
Data Bridge Market Research analyzes...
Mumbai to Nagpur Cab
Book Mumbai to Nagpur cab online at best price. CabBazar provides car rental services for all cab...
From Clicks to Pages: The Surprising Return of Printed Catalogs in Online Retail
In the era of click-to-cart convenience, it might seem odd to talk about printed catalogs....
Vellore to Yelagiri Cab
Book Vellore to Yelagiri cab online at best price. CabBazar provides car rental services for all...
Strengthening Recovery: Hernia Repair Devices Market Across 10 Major Countries
"Executive Summary (U.S., Canada, U.K., Germany, Italy, France, Spain, Japan, India, China,...