手册:sql.php
Appearance
From mediawiki.org
This page is a translated version of the page Manual:Sql.php and the translation is 80% complete.
Languages:
MediaWiki版本:
≥ 1.10
| MediaWiki文件: sql.php | |
|---|---|
| 位置: | maintenance/ |
| 源代码: | master • 1.45.1 • 1.44.3 • 1.43.6 |
| 类: | MwSql |
警告 警告: 从 MediaWiki 1.28 开始,sql.php 可能会有一些副作用。 在运行这个脚本之前,请确保你已经运行了 update.php 并且事情没有中断!
sql.php 是一个允许执行 SQL 查询的维护文件。
如果您将 SQL 文件作为第一个参数,它将替换 MediaWiki 特定的代码注释,例如 /*_*/ 用于配置的数据库前缀(以及其他)。
如果你不给它一个文件,那么你可以交互方式查询数据库,类似于 MySQL 命令行工具。
通常此脚本在您想升级 MediaWiki时被使用,但有一个大型的主/副本数据库设置并且不希望任何停机时间。
您可以不使用 update.php,而是使用 sql.php 在每个 sql 服务器上分别应用 sql/mysql 目录中的数据库单个补丁,在架构更改运行时使单个服务器停止轮换。
通常,您应该只在必须时才这样做 - 大多数用户应该改用 update.php 脚本。
选项/参数
命令行中此脚本的可用选项包括:
| 選項 | 描述 | Required? |
|---|---|---|
| --query | Run a single query instead of running interactively | Optional |
| --json | Output the results as JSON instead of PHP objects | Optional |
| --status | Return successful exit status only if the query succeeded (selected or altered rows), otherwise 1 for errors, 2 for no rows | Optional |
| --cluster | 允许为命令提供集群名称。 | Optional |
| --wikidb | 如果不是当前数据库,则允许通过 ID 在命令中使用不同的数据库。 | Optional |
| --replicadb | Replica DB server to use instead of the primary DB (can be "any") | Optional |
用法
phpmaintenance/run.phpsql[--query|--json|--status|--cluster|--wikidb|--replicadb]
交互模式
Terminal
$ php maintenance/run.php sql >
内联查询
Terminal
$ php maintenance/run.php sql --query "SELECT user_name from user;" --json
[
{
"user_name": "Delete page script"
},
{
"user_name": "Foo"
},
{
"user_name": "Maintenance script"
},
{
"user_name": "MediaWiki default"
},
{
"user_name": "ScriptImporter"
}
]
应用补丁
Terminal
$ php maintenance/run.php sql sql/mysql/patch-actor-table.sql Query OK, 0 row(s) affected Query OK, 0 row(s) affected Query OK, 0 row(s) affected