开发者

How do I tell Django to use MySql from a WAMP install?

开发者 https://www.devze.com 2022-12-31 22:07 出处:网络
I\'ve had Django running with Sqlite for a while. I then installed WAMP, and I now want to get ready for a production run, and would like to switch to MySql. Is there a straightforward way of telling

I've had Django running with Sqlite for a while. I then installed WAMP, and I now want to get ready for a production run, and would like to switch to MySql. Is there a straightforward way of telling it about the MySql instance that is running with WAMP开发者_如何学JAVA?


as Ignacio already has pointed out you have to modify your settings.py. If you are using the latest version of Django (that would be 1.2.x) youe settings.py will contain this section:

DATABASES = {
    'default': {
        'ENGINE': '',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

Here you can define which database you are using.

In your case this section should look like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '',
        'USER': 'your-mysql-username',
        'PASSWORD': 'your-mysql-users-password',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

If your are running a MySQL server it is identified by its IP address (localhost = 127.0.0.1) and its port (3306). You could run several MySQL server instances on the same computer. Each of this instances could be identified by the combination of its IP and port.

Hope that helps you.


Modify the database options in settings.py.


By default, these are the settings you should use with WAMP/MySQL I believe...

DATABASE_ENGINE = 'django.db.backends.mysql'
DATABASE_NAME = ''
DATABASE_USER = 'root'
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''


first install mysqldb module for python by typing following command:

easy_install mysql-python

on command prompt/python client and then modify your settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'Database Name',
        'USER': 'Database Username',
        'PASSWORD': 'Database Password',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消