如何告诉Django从WAMP安装使用MySql ?

时间:2023-01-12 19:01:15

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?

我已经让Django和Sqlite一起运行一段时间了。然后我安装了WAMP,现在我想为生产运行做好准备,并想切换到MySql。有没有一种简单的方法告诉它使用WAMP运行的MySql实例?

4 个解决方案

#1


3  

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:

正如伊格纳西奥已经指出的,您必须修改您的settings.y。如果您正在使用最新版本的Django(即1.2.x)设置。py将包含以下部分:

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.

如果您正在运行MySQL服务器,那么它将通过其IP地址(localhost = 127.0.0.1)和端口(3306)进行标识。您可以在同一台计算机上运行几个MySQL服务器实例。每个实例都可以通过其IP和端口的组合来标识。

Hope that helps you.

希望可以帮助你。

#2


1  

Modify the database options in settings.py.

修改settings.y中的数据库选项。

#3


0  

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

默认情况下,我认为WAMP/MySQL应该使用这些设置……

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

#4


0  

first install mysqldb module for python by typing following command:

首先为python安装mysqldb模块,输入以下命令:

easy_install mysql-python

easy_install mysql-python

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

在命令提示符/python客户端,然后修改设置。

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

#1


3  

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:

正如伊格纳西奥已经指出的,您必须修改您的settings.y。如果您正在使用最新版本的Django(即1.2.x)设置。py将包含以下部分:

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.

如果您正在运行MySQL服务器,那么它将通过其IP地址(localhost = 127.0.0.1)和端口(3306)进行标识。您可以在同一台计算机上运行几个MySQL服务器实例。每个实例都可以通过其IP和端口的组合来标识。

Hope that helps you.

希望可以帮助你。

#2


1  

Modify the database options in settings.py.

修改settings.y中的数据库选项。

#3


0  

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

默认情况下,我认为WAMP/MySQL应该使用这些设置……

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

#4


0  

first install mysqldb module for python by typing following command:

首先为python安装mysqldb模块,输入以下命令:

easy_install mysql-python

easy_install mysql-python

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

在命令提示符/python客户端,然后修改设置。

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