Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
Double check whether 'python' database exists at localhost:3306 –  vminof Jun 25 at 12:12
    
You have installed MySQL Workbench, but have you installed MySQL Server ?? Look at your OS services. –  kmas Jun 25 at 12:23
    
yes MySQL Server is running on the localhost –  Lochster395 Jun 25 at 12:27
    
Ok, so I think the answer I've given below is enough for you to create your database. Tell me in the answer comments if you have another problem or misunderstanding. ;) –  kmas Jun 25 at 12:31
add comment

1 Answer

up vote 3 down vote accepted

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).

share|improve this answer
    
I've exported it as highlighted but how do i do the rest? (as you can tell I'm no SQL expert) (I'd also rather not use phpMyAdmin if at all possible) –  Lochster395 Jun 25 at 12:30
    
The graphical way : create a connection in MySQL Workbench. A shell way, launch the MySQL command line tool and execute/copy the exported file in it. –  kmas Jun 25 at 12:33
    
How do i get the connection to link to python? –  Lochster395 Jun 25 at 12:46
    
Your python code is certainly OK (I don't know python by the way ;) ). The problem is that you have a MySQL server, but you have not created the python database you want to connect to in your python code. A MySQL Workbench connection is only used in MySQL Workbench ! ;) The SQL create script lets you create easyly your database, that's all. –  kmas Jun 25 at 12:50
    
I have added another image for you. –  kmas Jun 25 at 12:52
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.