Hado
Hado

Reputation: 39

MySQLdb Error: 'Unknown Database Python' using MySQL Workbench

When i run the code below in python 2.7.7, i get the error also below.

code:

    import MySQLdb

    db = MySQLdb.connect(
        host="localhost",
        port=3306,
        user="root",
        passwd="mypassword",
        db="python"
    )

error: '_mysql_exceptions.OperationalError: (1049, "Unknown database 'python'")'

The database was made using MySQL Workbench and saved to the desktop (same location as python file) with the name python. I'm not using Django or anything like that and can't find answers where the person isn't using it. Please help.

Upvotes: 1

Views: 5955

Answers (1)

kmas
kmas

Reputation: 6439

MySQL Workbench produces a .mwb file which is not a database. This file is only a Entity-Relationship schema (which is very useful).

You have to export a SQL create script of your schema.

Menu File > Export > Forward Engineer SQL CREATE script

enter image description here

Then you execute this script (a .sql file) that will create your database.

For example, you can do it with :

  • MySQL command
  • phpMyAdmin
  • MySQL workbench (through a connection)

Create a MySQL Workbench connection :

enter image description here

Copy and execute your SQL create script :

enter image description here

Your schema have to be like this in your case (database name) :

enter image description here

For your information a MySQL database is used through an IP/port, not through a file (SQLite is a file database for example, not MySQL).

Upvotes: 5

Related Questions