Home > Enterprise >  Create my database in python but i can't find it
Create my database in python but i can't find it

Time:02-27

I create my database with python

    import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="126332"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")

but after goto cmd and mysql 8.0 command Line and run this command

mysql> SHOW DATABASEs;
 -------------------- 
| Database           |
 -------------------- 
| information_schema |
| mysql              |
| payroll            |
| performance_schema |
| sys                |
 -------------------- 
5 rows in set (0.28 sec)

but i can't see my database "mydatabase"

where is it?

when goto to my code and run this code i see my database

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="126332"
)

mycursor = mydb.cursor()

mycursor.execute("SHOW DATABASES")

for x in mycursor:
  print(x)

RESULT:

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

CodePudding user response:

    import mysql.connector

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

mycursor = mydb.cursor()

#check database list:

    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) 

mycursor.execute("CREATE DATABASE mydatabase")
  • Related