django 连接mysql
jopen
9年前
替换默认数据库配置
vi sites/settings.py ''' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } ''' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME':'django', 'USER':'root', 'HOST':'localhost', 'PASSWORD':'', 'PORT':'3306', } }
设置数据库编码 vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 character_set_server=utf8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [client] default-character_set=utf8
创建数据库 mysql -uroot create database django character set utf8 exit sudo service mysqld restart
参考地址: http://blog.csdn.net/luoweifu/article/details/8832492