标签:image 启动 虚拟环境安装 strong databases 服务器 查看 命令 col
准备: 云服务器上安装mysql
本地虚拟环境安装mysqlclient(下载地址): python -m pip install mysqlclient-1.4.4-cp36-cp36m-win_amd64.whl
# root账号登录 mysql -u root -p # 创建数据库 — mysite_db create database mysite_db default charset=utf8mb4 default collate utf8mb4_unicode_ci; # 创建账号设置密码并赋予任意主机访问权限 create user ‘user‘@‘%‘ identified by ‘password‘; # 添加权限到数据库(mysite_db) GRANT ALL PRIVILEGES ON mysite_db.* TO ‘user‘@‘%‘IDENTIFIED BY ‘password‘ WITH GRANT OPTION; # 刷新权限(授权之后必须刷新权限才生效) FLUSH PRIVILEGES;
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘NAME‘: ‘数据库名‘, ‘USER‘: ‘用户名‘, ‘PASSWORD‘: ‘密码‘, ‘HOST‘: ‘IP‘, ‘PORT‘: ‘端口号‘, } }
迁移数据库: python manage.py migrate
生成缓存表:python manage.py createcachetable
运行项目并查看启动情况:python manage.py runserver
1. 还原settings.py的DATABASES为sqlite,把数据导出到data.json中: python manage.py dumpdata > data.json
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.sqlite3‘, ‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘), } }
2. 先删除MySQL中表django_content_type和auth_permission的所有数据,防止导入数据报错数据重复
输入: delete from auth_permission;
delete from django_content_type;
3. 再把settings.py的DATABASES修改回mysql,并导入数据输入python manage.py loaddata data.json
4. mysql加载时区表,命令行执行: mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p
django -> 博客项目sqlite数据迁移至mysql
标签:image 启动 虚拟环境安装 strong databases 服务器 查看 命令 col
原文地址:https://www.cnblogs.com/SitVen/p/11681739.html