签入版本
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
# 11.3 数据库迁移
|
||||
|
||||
:::tip CLI 迁移工具
|
||||
除了 SQL 脚本导入,项目还提供了 `php think db:migrate` 命令行工具,支持跨数据库自动迁移(MySQL → PostgreSQL 等),自动迁移索引、外键、字段注释、表注释、默认值和排序规则(collation),数据迁移基于主键稳定排序并支持事务回滚,详见 [7.6 数据库迁移工具](/zh/tools/db-migrate.html)。
|
||||
:::
|
||||
|
||||
## SQL 脚本目录
|
||||
|
||||
```text
|
||||
document/
|
||||
├── mysql/rxthinkcmf.thinkphp6.elevue.sql # MySQL 版本(约 78 万行)
|
||||
├── postgresql/rxthinkcmf.thinkphp6.elevue.sql # PostgreSQL 版本
|
||||
├── sqlserver/rxthinkcmf.thinkphp6.elevue.sql # SQL Server 版本
|
||||
├── oracle/rxthinkcmf.thinkphp6.elevue.sql # Oracle 版本
|
||||
└── sqlite/rxthinkcmf.thinkphp6.elevue.sql # SQLite 版本
|
||||
```
|
||||
|
||||
各数据库脚本已针对对应的 SQL 语法做了适配,可直接导入。
|
||||
|
||||
## 各数据库导入命令
|
||||
|
||||
### MySQL
|
||||
|
||||
```bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# MySQL 导入(mysql 命行工具)
|
||||
# -----------------------------------------------------------------------------
|
||||
# -u root -proot → 用户名和密码
|
||||
# rxthinkcmf... → 目标数据库名
|
||||
# < file.sql → 将 SQL 文件作为输入执行
|
||||
mysql -u root -proot rxthinkcmf.thinkphp6.elevue < document/mysql/rxthinkcmf.thinkphp6.elevue.sql
|
||||
```
|
||||
|
||||
### PostgreSQL
|
||||
|
||||
```bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# PostgreSQL 导入(psql 命令行工具)
|
||||
# -----------------------------------------------------------------------------
|
||||
# -U postgres → 连接用户
|
||||
# -d ... → 目标数据库
|
||||
# -f file.sql → 执行 SQL 文件
|
||||
psql -U postgres -d rxthinkcmf.thinkphp6.elevue -f document/postgresql/rxthinkcmf.thinkphp6.elevue.sql
|
||||
```
|
||||
|
||||
### SQL Server
|
||||
|
||||
```bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# SQL Server 导入(sqlcmd 命令行工具)
|
||||
# -----------------------------------------------------------------------------
|
||||
# -S localhost → 服务器地址
|
||||
# -U sa → 用户名(sa 为管理员)
|
||||
# -P root → 密码
|
||||
# -d ... → 目标数据库
|
||||
# -i file.sql → 执行 SQL 文件
|
||||
sqlcmd -S localhost -U sa -P root -d rxthinkcmf.thinkphp6.elevue -i document/sqlserver/rxthinkcmf.thinkphp6.elevue.sql
|
||||
```
|
||||
|
||||
### Oracle
|
||||
|
||||
```bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# Oracle 导入(sqlplus 命令行工具)
|
||||
# -----------------------------------------------------------------------------
|
||||
# root/root@localhost:1521/XE → 用户/密码@主机:端口/服务名
|
||||
# @file.sql → 执行 SQL 文件
|
||||
sqlplus root/root@localhost:1521/XE @document/oracle/rxthinkcmf.thinkphp6.elevue.sql
|
||||
```
|
||||
|
||||
### SQLite
|
||||
|
||||
```bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# SQLite 导入(sqlite3 命令行工具)
|
||||
# -----------------------------------------------------------------------------
|
||||
# 数据库文件路径 → SQLite 数据库存储在单个文件中
|
||||
# < file.sql → 将 SQL 文件作为输入执行
|
||||
sqlite3 /www/api/runtime/database.sqlite < document/sqlite/rxthinkcmf.thinkphp6.elevue.sql
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 每种数据库的主脚本已做语法适配,无需手动转换
|
||||
- 导入前请先创建数据库并配置好用户权限
|
||||
- 详见 [2.4 数据库初始化](/zh/quickstart/database-init.html)
|
||||
Reference in New Issue
Block a user