MediaWiki version:
1.10
MediaWiki file: sql.php
Location: maintenance/
Source code: master 1.40.0 1.39.4 1.35.11
Classes: MwSql

Warning Warning: Since MediaWiki 1.28, sql.php may have some side effect. Please make sure you have run update.php and things do not break before running this script!

sql.php is a maintenance file which allows performing SQL queries. If you give an SQL file as the first argument, it will replace MediaWiki specific code comments like /*_*/ for the configured database prefix (among others). If you don't give it a file, then you can query the database in an interactive fashion, similar to the MySQL command line tool.

This script is often used if you want to upgrade MediaWiki, but have a large, master/replica-database setup and don't want any downtime. Instead of using update.php, you might use sql.php to apply database individual patches from maintenance/archives directory on each sql server separately, taking the individual server out of rotation while the schema change runs. Generally you should only do this if you have to - most users should use the update.php script instead.

Options/Arguments

Available options for this script from the command line are:

Option Description Required?
--query Run a single query instead of running interactivelyOptional
--json Output the results as JSON instead of PHP objectsOptional
--status Return successful exit status only if the query succeeded (selected or altered rows), otherwise 1 for errors, 2 for no rowsOptional
--cluster Allows a cluster name to be provided for the command.Optional
--wikidb Allows for a different database to be used in the command by ID if not the current database.Optional
--replicadb Replica DB server to use instead of the primary DB (can be "any")Optional

Usage

php maintenance/sql.php [ --query| --json| --status| --cluster| --wikidb| --replicadb ]

Interactive mode

Terminal
$ php maintenance/sql.php

>

Inline query

Terminal
$ php maintenance/sql.php --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"
    }
]

Applying patches

Terminal
$ php maintenance/sql.php maintenance/archives/patch-actor-table.sql

Query OK, 0 row(s) affected
Query OK, 0 row(s) affected
Query OK, 0 row(s) affected

See also

  • Manual:Mysql.php
  • Manual:Sqlite.php
  • Manual:GenerateSchemaSql.php
  • Manual:Update.php
This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.