51Testing软件测试论坛
标题:
django 连接mysql
[打印本页]
作者:
测试积点老人
时间:
2019-1-2 15:25
标题:
django 连接mysql
替换默认数据库配置
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
复制代码
作者:
Miss_love
时间:
2020-12-28 09:24
学习
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2