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)
Căutare
Categorii
- Information Technology
- Office Equipment and Supplies
- Cars and Trucks
- Persons
- Books and Authors
- Tutorials
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Jocuri
- Gardening
- Health
- Home
- Literature
- Music
- Networking
- Alte
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Citeste mai mult
Anti-Seize Compounds Market Unveiling Driving Factors, Strategies, and Forecasted Trends by Fact MR
The anti-seize compounds market is valued at USD 201.9 million in 2025. As per Fact.MR...
Top 10 Reasons to Visit Kazakhstan This Year
Kazakhstan is a country which presents a truly outstanding combination of unspoiled nature,...
Why Performance Marketing is Crucial for Businesses in Kerala
In today's competitive digital landscape, businesses across Kerala are seeking measurable...
© 2025 Omaada - A global social and professionals networking platform
Romaian
