CINXE.COM
Help:Toolforge/Database - Wikitech
<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-disabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Help:Toolforge/Database - Wikitech</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-disabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )labswikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat": "dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"5e11234a-2ee3-4121-9b13-b0ed1ffffaac","wgCanonicalNamespace":"Help","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":12,"wgPageName":"Help:Toolforge/Database","wgTitle":"Toolforge/Database","wgCurRevisionId":2254601,"wgRevisionId":2254601,"wgArticleId":18678,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Toolforge","How-to-guide"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Help:Toolforge/Database","wgRelevantArticleId":18678,"wgIsProbablyEditable":false,"wgRelevantPageIsProbablyEditable":false,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikitech","wgCiteReferencePreviewsActive":true,"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgVisualEditor":{ "pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":40000,"wgEditSubmitButtonLabelPublish":true,"wgDiscussionToolsFeaturesEnabled":{"replytool":true,"newtopictool":true,"sourcemodetoolbar":true,"topicsubscription":false,"autotopicsub":false,"visualenhancements":false,"visualenhancements_reply":false,"visualenhancements_pageframe":false},"wgDiscussionToolsFallbackEditMode":"visual","wgULSPosition":"personal","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"wgSiteNoticeId":"2.0"};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user": "ready","user.options":"loading","ext.inputBox.styles":"ready","ext.pygments":"ready","ext.cite.styles":"ready","ext.discussionTools.init.styles":"ready","oojs-ui-core.styles":"ready","oojs-ui.styles.indicators":"ready","mediawiki.widgets.styles":"ready","oojs-ui-core.icons":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.pt":"ready","ext.dismissableSiteNotice.styles":"ready"};RLPAGEMODULES=["ext.pygments.view","ext.cite.ux-enhancements","mediawiki.page.media","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.site","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.discussionTools.init","ext.eventLogging", "ext.wikimediaEvents","ext.uls.interface","ext.checkUser.clientHints","ext.dismissableSiteNotice"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&modules=ext.cite.styles%7Cext.discussionTools.init.styles%7Cext.dismissableSiteNotice.styles%7Cext.inputBox.styles%7Cext.pygments%7Cext.uls.pt%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cmediawiki.widgets.styles%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui.styles.indicators%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles&only=styles&skin=vector-2022"> <script async="" src="/w/load.php?lang=en&modules=startup&only=scripts&raw=1&skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&modules=site.styles&only=styles&skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.6"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Help:Toolforge/Database - Wikitech"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="icon" href="/static/favicon/wikitech.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikitech (en)"> <link rel="EditURI" type="application/rsd+xml" href="//wikitech.wikimedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://wikitech.wikimedia.org/wiki/Help:Toolforge/Database"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"> <link rel="alternate" type="application/atom+xml" title="Wikitech Atom feed" href="/w/index.php?title=Special:RecentChanges&feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="login.wikimedia.org"> </head> <body class="ext-discussiontools-replytool-enabled ext-discussiontools-newtopictool-enabled ext-discussiontools-sourcemodetoolbar-enabled skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-12 ns-subject page-Help_Toolforge_Database rootpage-Help_Toolforge skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes in the wiki [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-Server-admin-log:-Prod" class="mw-list-item"><a href="/wiki/Server_Admin_Log"><span>Server admin log: Prod</span></a></li><li id="n-Admin-log:-RelEng" class="mw-list-item"><a href="/wiki/Release_Engineering/SAL"><span>Admin log: RelEng</span></a></li><li id="n-Incident-status" class="mw-list-item"><a href="/wiki/Incident_status"><span>Incident status</span></a></li><li id="n-Deployments" class="mw-list-item"><a href="/wiki/Deployments"><span>Deployments</span></a></li><li id="n-SRE-Team-Help" class="mw-list-item"><a href="/wiki/SRE/SRE_Team_requests"><span>SRE Team Help</span></a></li> </ul> </div> </div> <div id="p-Cloud_VPS_&_Toolforge" class="vector-menu mw-portlet mw-portlet-Cloud_VPS_Toolforge" > <div class="vector-menu-heading"> Cloud VPS & Toolforge </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-Cloud-VPS-portal" class="mw-list-item"><a href="/wiki/Portal:Cloud_VPS"><span>Cloud VPS portal</span></a></li><li id="n-Toolforge-portal" class="mw-list-item"><a href="/wiki/Portal:Toolforge"><span>Toolforge portal</span></a></li><li id="n-Request-VPS-project" class="mw-list-item"><a href="https://phabricator.wikimedia.org/project/view/2875/"><span>Request VPS project</span></a></li><li id="n-Admin-log:-Cloud-VPS" class="mw-list-item"><a href="/wiki/Cloud_VPS_Server_Admin_Log"><span>Admin log: Cloud VPS</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikitech.svg" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikitech" src="/static/images/mobile/copyright/wikitech-wordmark.svg" style="width: 8.75em; height: 1.6875em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikitech [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikitech" aria-label="Search Wikitech" autocapitalize="sentences" title="Search Wikitech [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-uls" class="mw-list-item active user-links-collapsible-item"><a data-mw="interface" href="#" class="uls-trigger cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet"><span class="vector-icon mw-ui-icon-wikimedia-language mw-ui-icon-wikimedia-wikimedia-language"></span> <span>English</span></a> </li> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page's font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/?wmf_source=donate&wmf_medium=sidebar&wmf_campaign=wikitech.wikimedia.org&uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&returnto=Help%3AToolforge%2FDatabase" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out user-links-collapsible-item" title="More options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/?wmf_source=donate&wmf_medium=sidebar&wmf_campaign=wikitech.wikimedia.org&uselang=en"><span>Donate</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&returnto=Help%3AToolforge%2FDatabase" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><div id="mw-dismissablenotice-anonplace"></div><script>(function(){var node=document.getElementById("mw-dismissablenotice-anonplace");if(node){node.outerHTML="\u003Cdiv class=\"mw-dismissable-notice\"\u003E\u003Cdiv class=\"mw-dismissable-notice-close\"\u003E[\u003Ca tabindex=\"0\" role=\"button\"\u003Edismiss\u003C/a\u003E]\u003C/div\u003E\u003Cdiv class=\"mw-dismissable-notice-body\"\u003E\u003C!-- CentralNotice --\u003E\u003Cdiv id=\"localNotice\" data-nosnippet=\"\"\u003E\u003Cdiv class=\"sitenotice\" lang=\"en\" dir=\"ltr\"\u003E\u003Ctable style=\"width: 75%; background-color: var(--background-color-warning-subtle, #fdf2d5); border: var(--border-subtle, 1px solid #987027); color: var(--color-base, #202122); border-radius: 10px; padding: 5px; margin: 0 auto;\"\u003E\n\u003Ctbody\u003E\u003Ctr\u003E\n\u003Ctd style=\"width:40px; height:40px; text-align:center; vertical-align:middle; padding: 2px;\"\u003E\u003Cspan typeof=\"mw:File\"\u003E\u003Ca href=\"/wiki/File:OOjs_UI_icon_alert-warning.svg\" class=\"mw-file-description\"\u003E\u003Cimg src=\"//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/OOjs_UI_icon_alert-warning.svg/30px-OOjs_UI_icon_alert-warning.svg.png\" decoding=\"async\" width=\"30\" height=\"30\" class=\"mw-file-element\" srcset=\"//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/OOjs_UI_icon_alert-warning.svg/45px-OOjs_UI_icon_alert-warning.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/3b/OOjs_UI_icon_alert-warning.svg/60px-OOjs_UI_icon_alert-warning.svg.png 2x\" data-file-width=\"20\" data-file-height=\"20\" /\u003E\u003C/a\u003E\u003C/span\u003E\n\u003C/td\u003E\n\u003Ctd style=\"text-align:center; vertical-align: middle; padding: 4px; max-height: 60px;\"\u003E\u003Cb\u003EWe are migrating Wikitech to \u003Ca href=\"/wiki/Wikitech/SUL-migration\" title=\"Wikitech/SUL-migration\"\u003ESUL\u003C/a\u003E!\u003C/b\u003E\n\u003Cp\u003E\u003Cb\u003EAction may be required for your \u003Ca href=\"/wiki/Wikitech/SUL-migration#What_You_Should_Do\" title=\"Wikitech/SUL-migration\"\u003E account\u003C/a\u003E!\u003C/b\u003E\n\u003C/p\u003E\u003Cp\u003E\u003Cb\u003ETrouble logging in? Please visit \u003Ca href=\"https://phabricator.wikimedia.org/T376267\" class=\"extiw\" title=\"phab:T376267\"\u003ET376267\u003C/a\u003E\u003C/b\u003E\n\u003C/p\u003E\n\u003C/td\u003E\u003C/tr\u003E\u003C/tbody\u003E\u003C/table\u003E\n\u003Cp\u003E\u003Cbr /\u003E\n\u003C/p\u003E\n\u003Chr /\u003E\n\u003Cp\u003E\u003Cbr /\u003E\nPlease take the \u003Ca rel=\"nofollow\" class=\"external text\" href=\"https://wikimediafoundation.limesurvey.net/986172\"\u003EDecember 2024 Developer Satisfaction Survey\u003C/a\u003E\u003Csup\u003E(\u003Ca href=\"https://foundation.wikimedia.org/wiki/Legal:Developer_Satisfaction_Survey_2024_Privacy_Statement\" class=\"extiw\" title=\"foundation:Legal:Developer Satisfaction Survey 2024 Privacy Statement\"\u003Eprivacy statement\u003C/a\u003E)\u003C/sup\u003E anytime before 2025-01-03. This survey helps us prioritize work on tools and platforms for our technical contributors.\n\u003C/p\u003E\u003C/div\u003E\u003C/div\u003E\u003C/div\u003E\u003C/div\u003E";}}());</script></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">Beginning</div> </a> </li> <li id="toc-Connecting_to_the_database_replicas" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Connecting_to_the_database_replicas"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Connecting to the database replicas</span> </div> </a> <button aria-controls="toc-Connecting_to_the_database_replicas-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Connecting to the database replicas subsection</span> </button> <ul id="toc-Connecting_to_the_database_replicas-sublist" class="vector-toc-list"> <li id="toc-Naming_conventions" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Naming_conventions"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1</span> <span>Naming conventions</span> </div> </a> <ul id="toc-Naming_conventions-sublist" class="vector-toc-list"> <li id="toc-analytics_vs_web" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#analytics_vs_web"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1.1</span> <span>analytics vs web</span> </div> </a> <ul id="toc-analytics_vs_web-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Language_codes_and_project_families" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Language_codes_and_project_families"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1.2</span> <span>Language codes and project families</span> </div> </a> <ul id="toc-Language_codes_and_project_families-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Shards" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Shards"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1.3</span> <span>Shards</span> </div> </a> <ul id="toc-Shards-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Old_names" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Old_names"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1.4</span> <span>Old names</span> </div> </a> <ul id="toc-Old_names-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Connection_handling_policy" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Connection_handling_policy"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2</span> <span>Connection handling policy</span> </div> </a> <ul id="toc-Connection_handling_policy-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3</span> <span>Connecting to the wiki replicas from other Cloud VPS projects</span> </div> </a> <ul id="toc-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Connecting_to_the_database_replicas_from_your_own_computer" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Connecting_to_the_database_replicas_from_your_own_computer"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.4</span> <span>Connecting to the database replicas from your own computer</span> </div> </a> <ul id="toc-Connecting_to_the_database_replicas_from_your_own_computer-sublist" class="vector-toc-list"> <li id="toc-SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.4.1</span> <span>SSH tunneling for local testing which makes use of Wiki Replica databases</span> </div> </a> <ul id="toc-SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-TLS_connection_failures" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#TLS_connection_failures"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.5</span> <span>TLS connection failures</span> </div> </a> <ul id="toc-TLS_connection_failures-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Databases" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Databases"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Databases</span> </div> </a> <button aria-controls="toc-Databases-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Databases subsection</span> </button> <ul id="toc-Databases-sublist" class="vector-toc-list"> <li id="toc-Replica_database_schema_(tables_and_indexes)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Replica_database_schema_(tables_and_indexes)"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>Replica database schema (tables and indexes)</span> </div> </a> <ul id="toc-Replica_database_schema_(tables_and_indexes)-sublist" class="vector-toc-list"> <li id="toc-Stability_of_the_mediawiki_database_schema" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Stability_of_the_mediawiki_database_schema"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1.1</span> <span>Stability of the mediawiki database schema</span> </div> </a> <ul id="toc-Stability_of_the_mediawiki_database_schema-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Tables_for_revision_or_logging_queries_involving_user_names_and_IDs" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Tables_for_revision_or_logging_queries_involving_user_names_and_IDs"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1.2</span> <span>Tables for revision or logging queries involving user names and IDs</span> </div> </a> <ul id="toc-Tables_for_revision_or_logging_queries_involving_user_names_and_IDs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Redacted_tables" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Redacted_tables"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1.3</span> <span>Redacted tables</span> </div> </a> <ul id="toc-Redacted_tables-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Unavailable_tables" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Unavailable_tables"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1.4</span> <span>Unavailable tables</span> </div> </a> <ul id="toc-Unavailable_tables-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Metadata_database" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Metadata_database"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2</span> <span>Metadata database</span> </div> </a> <ul id="toc-Metadata_database-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Identifying_lag" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Identifying_lag"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3</span> <span>Identifying lag</span> </div> </a> <ul id="toc-Identifying_lag-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-User_databases" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#User_databases"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4</span> <span>User databases</span> </div> </a> <ul id="toc-User_databases-sublist" class="vector-toc-list"> <li id="toc-Privileges_on_the_database" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Privileges_on_the_database"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4.1</span> <span>Privileges on the database</span> </div> </a> <ul id="toc-Privileges_on_the_database-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Steps_to_create_a_user_database" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Steps_to_create_a_user_database"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4.2</span> <span>Steps to create a user database</span> </div> </a> <ul id="toc-Steps_to_create_a_user_database-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-ToolsDB_read-only_replica_host" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#ToolsDB_read-only_replica_host"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4.3</span> <span>ToolsDB read-only replica host</span> </div> </a> <ul id="toc-ToolsDB_read-only_replica_host-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-ToolsDB_Backups" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#ToolsDB_Backups"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4.4</span> <span>ToolsDB Backups</span> </div> </a> <ul id="toc-ToolsDB_Backups-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-ToolsDB_Caveats" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#ToolsDB_Caveats"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.4.5</span> <span>ToolsDB Caveats</span> </div> </a> <ul id="toc-ToolsDB_Caveats-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> </ul> </li> <li id="toc-Query_Limits" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Query_Limits"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Query Limits</span> </div> </a> <ul id="toc-Query_Limits-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Example_queries" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Example_queries"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Example queries</span> </div> </a> <ul id="toc-Example_queries-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Connecting_with..." class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Connecting_with..."> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>Connecting with...</span> </div> </a> <button aria-controls="toc-Connecting_with...-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Connecting with... subsection</span> </button> <ul id="toc-Connecting_with...-sublist" class="vector-toc-list"> <li id="toc-MySQL_Workbench" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#MySQL_Workbench"> <div class="vector-toc-text"> <span class="vector-toc-numb">5.1</span> <span>MySQL Workbench</span> </div> </a> <ul id="toc-MySQL_Workbench-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Code_samples_for_common_languages" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Code_samples_for_common_languages"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Code samples for common languages</span> </div> </a> <button aria-controls="toc-Code_samples_for_common_languages-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Code samples for common languages subsection</span> </button> <ul id="toc-Code_samples_for_common_languages-sublist" class="vector-toc-list"> <li id="toc-Bash" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Bash"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.1</span> <span>Bash</span> </div> </a> <ul id="toc-Bash-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-C" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#C"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.2</span> <span>C</span> </div> </a> <ul id="toc-C-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Perl" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Perl"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.3</span> <span>Perl</span> </div> </a> <ul id="toc-Perl-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Python" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Python"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.4</span> <span>Python</span> </div> </a> <ul id="toc-Python-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Python:_Django" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Python:_Django"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.5</span> <span>Python: Django</span> </div> </a> <ul id="toc-Python:_Django-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-PHP_(using_PDO)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#PHP_(using_PDO)"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.6</span> <span>PHP (using PDO)</span> </div> </a> <ul id="toc-PHP_(using_PDO)-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-PHP_(using_MySQLi)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#PHP_(using_MySQLi)"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.7</span> <span>PHP (using MySQLi)</span> </div> </a> <ul id="toc-PHP_(using_MySQLi)-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Java" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Java"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.8</span> <span>Java</span> </div> </a> <ul id="toc-Java-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Node.js" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Node.js"> <div class="vector-toc-text"> <span class="vector-toc-numb">6.9</span> <span>Node.js</span> </div> </a> <ul id="toc-Node.js-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-See_also" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#See_also"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>See also</span> </div> </a> <ul id="toc-See_also-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Note" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Note"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>Note</span> </div> </a> <ul id="toc-Note-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-namespace">Help</span><span class="mw-page-title-separator">:</span><span class="mw-page-title-main">Toolforge/Database</span></h1> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-help" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Help:Toolforge/Database" title="View the help page [c]" accesskey="c"><span>Help page</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Help_talk:Toolforge/Database" rel="discussion" title="Discussion about the content page [t]" accesskey="t"><span>Discussion</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Help:Toolforge/Database"><span>Read</span></a></li><li id="ca-viewsource" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&action=edit" title="This page is protected. You can view its source [e]" accesskey="e"><span>View source</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Help:Toolforge/Database"><span>Read</span></a></li><li id="ca-more-viewsource" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&action=edit"><span>View source</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Help:Toolforge/Database" title="A list of all wiki pages that link here [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Help:Toolforge/Database" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&oldid=2254601" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&page=Help%3AToolforge%2FDatabase&id=2254601&wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlQ%C4%B1sald%C4%B1c%C4%B1s%C4%B1&url=https%3A%2F%2Fwikitech.wikimedia.org%2Fwiki%2FHelp%3AToolforge%2FDatabase"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrKodu&url=https%3A%2F%2Fwikitech.wikimedia.org%2Fwiki%2FHelp%3AToolforge%2FDatabase"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-create_a_book" class="mw-list-item"><a href="/w/index.php?title=Special:Book&bookcmd=book_creator&referer=Help%3AToolforge%2FDatabase"><span>Create a book</span></a></li><li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&page=Help%3AToolforge%2FDatabase&action=show-download-screen"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Help:Toolforge/Database&printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">From Wikitech</div> </div> <div id="contentSub"><div id="mw-content-subtitle"><div class="subpages">< <bdi dir="ltr"><a href="/wiki/Help:Toolforge" title="Help:Toolforge">Help:Toolforge</a></bdi></div></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><style data-mw-deduplicate="TemplateStyles:r2241375">.mw-parser-output .tpl-navsidebar{max-width:22em;background:var(--background-color-base,#fff);color:var(--color-base,#202122);border:1px solid var(--border-color-base,#a2a9b1);float:right;clear:right;margin:.5em 0 1em 1em}.mw-parser-output .tpl-navsidebar-floatright{float:right;clear:right;margin:.5em 0 1em 1em}.mw-parser-output .tpl-navsidebar-floatleft{float:left;clear:left;margin:.5em 1em 1em 0}.mw-parser-output .tpl-navsidebar-floatnone{float:none;clear:both;margin:.5em 0}.mw-parser-output .tpl-navsidebar-topimage{margin:0 0 16px 0}.mw-parser-output .tpl-navsidebar-title{margin:8px 16px;border-bottom:3px solid var(--border-color-muted,#eaecf0);font-size:20px;text-align:center}.mw-parser-output .tpl-navsidebar-image{margin:0 0 8px}.mw-parser-output .tpl-navsidebar-content{margin:0 0 16px 0;padding:0 8px}.mw-parser-output .tpl-navsidebar-heading{margin:8px 0;font-weight:bold}.mw-parser-output .tpl-navsidebar-foot{padding:0 8px;margin:0;text-align:right;font-size:smaller}@media not (min-width:720px){.mw-parser-output .tpl-navsidebar{float:none;clear:both;margin:.5em 0;max-width:none}}</style><div role="navigation" class="navigation-not-searchable tpl-navsidebar" style=""><p class="tpl-navsidebar-title"><a href="/wiki/Help:Toolforge" title="Help:Toolforge">Toolforge</a></p><div class="tpl-navsidebar-image"><figure class="mw-halign-center" typeof="mw:File"><a href="/wiki/File:Toolforge_logo.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Toolforge_logo.svg/50px-Toolforge_logo.svg.png" decoding="async" width="50" height="50" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Toolforge_logo.svg/75px-Toolforge_logo.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Toolforge_logo.svg/100px-Toolforge_logo.svg.png 2x" data-file-width="180" data-file-height="180"/></a><figcaption></figcaption></figure></div><div class="tpl-navsidebar-contents"><div class="tpl-navsidebar-content"> <div class="mw-inputbox-centered" style=""><form name="searchbox" class="searchbox mw-inputbox-form-inline" action="/wiki/Special:Search"><div class="cdx-text-input"><input class="mw-searchInput searchboxInput cdx-text-input__input" name="search" placeholder="Search Toolforge documentation" size="40" dir="ltr"/></div><input type="hidden" value="incategory:Toolforge" name="searchfilter"/> <input type="submit" name="fulltext" value="Search" class="cdx-button"/><input type="hidden" value="Search" name="fulltext"/></form></div> </div><div class="tpl-navsidebar-content"> <ul><li><a href="/wiki/Help:Cloud_Services_introduction" title="Help:Cloud Services introduction">Cloud Services overview</a></li> <li><a href="/wiki/Help:Toolforge" title="Help:Toolforge">Toolforge user docs</a></li> <li><a href="/wiki/Portal:Toolforge/Changelog" title="Portal:Toolforge/Changelog">Toolforge changelog</a></li></ul> </div><div class="tpl-navsidebar-content"> <p class="tpl-navsidebar-heading">Get started</p><p class="mw-empty-elt"> </p><ul><li><a href="/wiki/Help:Toolforge/Quickstart" title="Help:Toolforge/Quickstart"> Quickstart: set up and get access</a></li> <li><a href="/wiki/Portal:Toolforge/About_Toolforge" title="Portal:Toolforge/About Toolforge"> How Toolforge works</a></li> <li><a href="/wiki/Help:Toolforge/Terms_and_conditions" title="Help:Toolforge/Terms and conditions"> Rules you must follow</a></li> <li><a href="/wiki/Category:Tutorials" title="Category:Tutorials">Tutorials</a></li></ul> </div><div class="tpl-navsidebar-content"> <p class="tpl-navsidebar-heading">Build and run tools</p><p class="mw-empty-elt"> </p><ul><li><a href="/wiki/Help:Toolforge/Tool_accounts" title="Help:Toolforge/Tool accounts">Navigate tool accounts and files</a></li> <li><a href="/wiki/Help:Toolforge/Building_container_images" title="Help:Toolforge/Building container images">Build container images for tools</a></li> <li><a href="/wiki/Help:Toolforge/Web" title="Help:Toolforge/Web">Run a web service</a></li> <li><a href="/wiki/Help:Toolforge/Jobs_framework" title="Help:Toolforge/Jobs framework">Schedule and manage jobs</a></li> <li><a href="/wiki/Help:Toolforge/Envvars" title="Help:Toolforge/Envvars">Manage tool runtime configuration (envvars)</a></li> <li>Language-specific details: <ul><li><a href="/wiki/Help:Toolforge/Python" title="Help:Toolforge/Python">Python</a></li> <li><a href="/wiki/Help:Toolforge/Running_Pywikibot_scripts" title="Help:Toolforge/Running Pywikibot scripts">Pywikibot</a></li> <li><a href="/wiki/Help:Toolforge/Node.js" title="Help:Toolforge/Node.js">Node.js</a></li> <li><a href="/wiki/Help:Toolforge/PHP" title="Help:Toolforge/PHP">PHP</a></li> <li><a href="/wiki/Category:How-to-guide" title="Category:How-to-guide">...more languages/frameworks</a></li></ul></li> <li><a href="/wiki/Help:Toolforge/Redis" title="Help:Toolforge/Redis">Use Redis for caching</a></li> <li><a href="/wiki/Help:Toolforge/Elasticsearch" title="Help:Toolforge/Elasticsearch">Index content with Elasticsearch</a></li></ul> </div><div class="tpl-navsidebar-content"> <p class="tpl-navsidebar-heading">Access shared storage and databases</p><p class="mw-empty-elt"> </p><ul><li><a href="/wiki/Help:Shared_storage" title="Help:Shared storage">Access shared storage and public wiki dumps</a></li> <li><a class="mw-selflink selflink"> Access the Wiki Replicas databases</a></li> <li><a href="/wiki/Help:CirrusSearch_elasticsearch_replicas" title="Help:CirrusSearch elasticsearch replicas"> Access replica search indices</a></li> <li>Manage <a class="mw-selflink-fragment" href="#User_databases"> tool databases</a></li></ul> </div><div class="tpl-navsidebar-content"> <p class="tpl-navsidebar-heading">Share and maintain tools</p><p class="mw-empty-elt"> </p><ul><li><a href="/wiki/Help:Toolforge/Version_control" title="Help:Toolforge/Version control">Set up version control and code review</a></li> <li><a href="/wiki/Help:Toolforge/Developing_successful_tools" title="Help:Toolforge/Developing successful tools">Develop successful tools</a></li> <li><a class="external text" href="https://toolhub.wikimedia.org/">Find and share tools on Toolhub</a></li> <li><a href="/wiki/Help:Toolforge/Tool_accounts#Delete_a_tool_account" title="Help:Toolforge/Tool accounts"> Delete a tool</a></li> <li><a href="/wiki/Portal:Toolforge/Contributing" title="Portal:Toolforge/Contributing">Contribute to Toolforge</a></li></ul> </div><div class="tpl-navsidebar-content"> <p class="tpl-navsidebar-heading">Get help</p><p class="mw-empty-elt"> </p><ul><li><a href="/wiki/Help:Cloud_Services_communication" title="Help:Cloud Services communication"> How and where to get help</a></li> <li><a href="/wiki/Help:Toolforge/Troubleshooting" title="Help:Toolforge/Troubleshooting">Troubleshooting</a></li></ul> </div><div class="tpl-navsidebar-content"> <p class="tpl-navsidebar-heading">Useful links</p><p class="mw-empty-elt"> </p><ul><li><a href="/wiki/Portal:Toolforge/Admin" title="Portal:Toolforge/Admin">Toolforge admin docs</a></li> <li><a href="/wiki/Category:Toolforge_tools" title="Category:Toolforge tools">List of tools</a></li> <li><a class="external text" href="https://toolsadmin.wikimedia.org/">Toolforge Admin Console (toolsadmin)</a></li></ul> </div></div><p class="tpl-navsidebar-foot">[<span class="noprint plainlinks"><a class="external text" href="https://wikitech.wikimedia.org/w/index.php?title=Template:Toolforge_nav&action=edit"><span title="Edit this template">edit</span></a></span>]</p></div><style data-mw-deduplicate="TemplateStyles:r2199624">.mw-parser-output .mw-tpl-rellink{font-style:italic;padding-bottom:0.4em;padding-left:0;margin-bottom:0.4em;color:#555;border-bottom:1px solid var(--border-color-base,#a2a9b1)}</style> <div class="rellink mw-tpl-rellink">See also: <a href="/wiki/Help:Wiki_Replicas/Queries" title="Help:Wiki Replicas/Queries">Help:Wiki Replicas/Queries</a> and <a href="https://meta.wikimedia.org/wiki/Research:Quarry" class="extiw" title="m:Research:Quarry">m:Research:Quarry</a></div> <style data-mw-deduplicate="TemplateStyles:r2211903">.mw-parser-output .note{background-position:left 7px top 50%;padding:0.5em 0.5em 0.5em 40px;margin:0.5em 0;overflow:hidden;background-color:#f8f9fa;color:#333;background-repeat:no-repeat;border:1px solid #ddd}.mw-parser-output .note-inline{display:inline-block;vertical-align:middle}.mw-parser-output .note-info{background-color:#eaf3ff;color:#333;background-image:url("https://upload.wikimedia.org/wikipedia/commons/e/ec/OOjs_UI_icon_information-progressive.svg");background-size:25px;border-color:#a3caff;padding-left:40px;min-height:25px}.mw-parser-output .note-reminder{background-color:#fff9ea;color:#333;background-image:url("https://upload.wikimedia.org/wikipedia/commons/a/a8/OOjs_UI_icon_lightbulb-yellow.svg");background-size:25px;border-color:#fc3;min-height:25px}.mw-parser-output .note-warn{background-color:#fff9ea;color:#333;background-image:url("https://upload.wikimedia.org/wikipedia/commons/3/3b/OOjs_UI_icon_alert-warning.svg");background-size:25px;border-color:#fc3;min-height:25px}.mw-parser-output .note-error{background-color:#fee7e6;color:#333;background-image:url("https://upload.wikimedia.org/wikipedia/commons/b/bf/OOjs_UI_icon_notice-destructive.svg");background-size:25px;border-color:#c33;min-height:25px}@media screen{html.skin-theme-clientpref-night .mw-parser-output .note{background-color:transparent;color:inherit}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .note{background-color:transparent;color:inherit}}</style><div role="note" class="note note-info">This page can be improved by breaking up its content into other docs. See <a href="https://phabricator.wikimedia.org/T232404" class="extiw" title="phab:T232404">phab:T232404</a>. Contributions welcome!</div> <p>Tools and Toolforge users have access to two sets of databases: </p> <ul><li><a href="/wiki/Wiki_replicas" class="mw-redirect" title="Wiki replicas">wiki replicas</a> with read-only access to production MediaWiki data</li> <li><a href="#User_databases">user databases</a> (aka ToolsDB)</li></ul> <p>On the wiki replicas, private user data has been redacted (some rows are elided and/or some columns are made NULL depending on the table). For most practical purposes this is identical to the production databases and sharded into clusters in much the same way. </p><p>Database credentials are generated on account creation and placed in a file called <code>replica.my.cnf</code> in the home directory of both a Tool and a Tools user account. This file cannot be modified or removed by users. </p><p>Symlinking the access file can be practical: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>ln<span class="w"> </span>-s<span class="w"> </span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span><span class="nv">$HOME</span>/.my.cnf </pre></div> <p><br/> </p> <meta property="mw:PageProp/toc"/> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Connecting_to_the_database_replicas" data-mw-thread-id="h-Connecting_to_the_database_replicas"><span data-mw-comment-start="" id="h-Connecting_to_the_database_replicas"></span>Connecting to the database replicas<span data-mw-comment-end="h-Connecting_to_the_database_replicas"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Connecting_to_the_database_replicas","replies":["h-Naming_conventions-Connecting_to_the_database_replicas","h-Connection_handling_policy-Connecting_to_the_database_replicas","h-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects-Connecting_to_the_database_replicas","h-Connecting_to_the_database_replicas_from_your_own_computer-Connecting_to_the_database_replicas","h-TLS_connection_failures-Connecting_to_the_database_replicas"]}}--></div> <p>You can connect to the database replicas (and/or the cluster where a database replica is hosted) by specifying your access credentials and the alias of the cluster and replicated database. For example: </p><p>To connect to the English Wikipedia replica, specify the alias of the hosting cluster (enwiki.analytics.db.svc.wikimedia.cloud) and the alias of the database replica (enwiki_p): </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>mariadb<span class="w"> </span>--defaults-file<span class="o">=</span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span>-h<span class="w"> </span>enwiki.analytics.db.svc.wikimedia.cloud<span class="w"> </span>enwiki_p </pre></div> <p>To connect to the Wikidata cluster: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>mariadb<span class="w"> </span>--defaults-file<span class="o">=</span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span>-h<span class="w"> </span>wikidatawiki.analytics.db.svc.wikimedia.cloud </pre></div> <p>To connect to Commons cluster: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>mariadb<span class="w"> </span>--defaults-file<span class="o">=</span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span>-h<span class="w"> </span>commonswiki.analytics.db.svc.wikimedia.cloud </pre></div> <p>There is also a shortcut for connecting to the replicas: sql <dbname>[_p] The _p is optional, but implicit (i.e. the sql tool will add it if absent). </p><p>To connect to the English Wikipedia database replica using the shortcut, simply type: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>sql<span class="w"> </span>enwiki </pre></div> <p>To connect to ToolsDB where you can create and write to tables, type: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>sql<span class="w"> </span>tools </pre></div> <p>This sets server to "tools.db.svc.wikimedia.cloud" and db to "". It's equivalent to typing- </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>mariadb<span class="w"> </span>--defaults-file<span class="o">=</span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span>-h<span class="w"> </span>tools.db.svc.wikimedia.cloud </pre></div> <p><br/> </p> <div class="mw-heading mw-heading3"><h3 id="Naming_conventions" data-mw-thread-id="h-Naming_conventions-Connecting_to_the_database_replicas"><span data-mw-comment-start="" id="h-Naming_conventions-Connecting_to_the_database_replicas"></span>Naming conventions<span data-mw-comment-end="h-Naming_conventions-Connecting_to_the_database_replicas"></span></h3></div> <p>As a convenience, each mediawiki project database (enwiki, bgwiki, etc) has an alias to the cluster it is hosted on. The alias has the form: </p> <dl><dd><b>${PROJECT}</b>.{analytics,web}.db.svc.wikimedia.cloud</dd></dl> <p>where <b>${PROJECT}</b> is the internal database name of a hosted Wikimedia project. </p> <div class="mw-heading mw-heading4"><h4 id="analytics_vs_web" data-mw-thread-id="h-analytics_vs_web-Naming_conventions"><span data-mw-comment-start="" id="h-analytics_vs_web-Naming_conventions"></span>analytics vs web<span data-mw-comment-end="h-analytics_vs_web-Naming_conventions"></span></h4></div> <p>The choice of "analytics" or "web" is up to you. The analytics service name connects to Wiki Replica servers where SQL queries will be allowed to run for a longer duration (currently 3 hours instead of 5 minutes),<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> but at the cost of all queries being potentially slower. Use of the web service name should be reserved for webservices which are running queries that display to users. </p> <div class="mw-heading mw-heading4"><h4 id="Language_codes_and_project_families" data-mw-thread-id="h-Language_codes_and_project_families-Naming_conventions"><span data-mw-comment-start="" id="h-Language_codes_and_project_families-Naming_conventions"></span>Language codes and project families<span data-mw-comment-end="h-Language_codes_and_project_families-Naming_conventions"></span></h4></div> <p>Wikipedia project database names generally follow the format <b>${LANGUAGE_CODE}${PROJECT_FAMILY}</b>. <b>${LANGUAGE_CODE}</b> is the <a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes" class="extiw" title="w:List of ISO 639-1 codes">ISO 639 two-letter code</a> for the primary content language (e.g. <code>en</code> for English, <code>es</code> for Spanish, <code>bg</code> for Bulgarian, ...). <b>${PROJECT_FAMILY}</b> is an internal label for the wiki's project family (e.g. <code>wiki</code> for Wikipedia, <code>wiktionary</code> for Wiktionary, ...). Some wikis such as Meta-Wiki have database names that do not follow this pattern (<code>metawiki</code>). The full mapping of wikis to database names is available <a href="https://iw.toolforge.org/db-names" class="extiw" title="toolforge:db-names">via the db-names Toolforge tool</a>. </p><p>The replica database names themselves consist of the Wikimedia project name, suffixed with <code>_p</code> (an underscore, and a p), for example: </p> <dl><dd><code>enwiki_p</code> for the English Wikipedia replica</dd></dl> <div class="mw-heading mw-heading4"><h4 id="Shards" data-mw-thread-id="h-Shards-Naming_conventions"><span data-mw-comment-start="" id="h-Shards-Naming_conventions"></span>Shards<span data-mw-comment-end="h-Shards-Naming_conventions"></span></h4></div> <p>In addition each cluster can be accessed by the name of its <a class="external text" href="https://noc.wikimedia.org/db.php">Wikimedia production shard</a> which follows the format <b>s${SHARD_NUMBER}.{analytics,web}.db.svc.wikimedia.cloud</b> (for example, <code>s1.analytics.db.svc.wikimedia.cloud</code> hosts the <code>enwiki_p</code> database). The shard where a particular database is can change over time. You should only use the shard name for opening a database connection if your application requires it for specific performance reasons such as for heavily crosswiki tools which would otherwise open hundreds of database connections. </p> <div class="mw-heading mw-heading4"><h4 id="Old_names" data-mw-thread-id="h-Old_names-Naming_conventions"><span data-mw-comment-start="" id="h-Old_names-Naming_conventions"></span>Old names<span data-mw-comment-end="h-Old_names-Naming_conventions"></span></h4></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-warn">You may find outdated documentation that uses <code>*.labsdb</code> aliases (for example <i>enwiki.labsdb</i>) to refer to the Wiki Replica databases. These service names are deprecated and have not had new wikis added since January 2018. Please update the docs or code that you find these references in to use the <i>${PROJECT}.{analytics,web}.db.svc.wikimedia.cloud</i> naming convention.</div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-warn">You may find outdated documentation that uses <code>${project}.{analytics,web}.db.svc.eqiad.wmflabs</code> aliases (for example <i>enwiki.web.db.svc.eqiad.wmflabs</i>) to refer to the Wiki Replica databases. These service names are deprecated. Please update the docs or code that you find these references in to use the <i>${PROJECT}.{analytics,web}.db.svc.wikimedia.cloud</i> naming convention.</div> <div class="mw-heading mw-heading3"><h3 id="Connection_handling_policy" data-mw-thread-id="h-Connection_handling_policy-Connecting_to_the_database_replicas"><span data-mw-comment-start="" id="h-Connection_handling_policy-Connecting_to_the_database_replicas"></span>Connection handling policy<span data-mw-comment-end="h-Connection_handling_policy-Connecting_to_the_database_replicas"></span></h3></div> <p>Usage of connection pools (maintaining open connections without them being in use), persistent connections, or any kind of connection pattern that maintains several connections open even if they are unused <b>is not permitted</b> on shared MariaDB instances (Wiki Replicas and ToolsDB). </p><p>The memory and processing power available to the database servers is a finite resource. Each open connection to a database, even if inactive, consumes some of these resources. Given the number of potential users for the Wiki Replicas and ToolsDB, if even a relatively small percentage of users held open idle connections, the server would quickly run out of resources to allow new connections. Please close your connections as soon as you stop using them. Note that connecting interactively and being idle for a few minutes is not an issue—opening dozens of connections and maintaining them automatically open is. </p><p>Idle connections can and will be killed by database and system administrators when discovered. If you (for example, by connector configuration or application policy) then reopen those connections automatically and keep them idle, you will be warned to stop. </p> <div class="mw-heading mw-heading3"><h3 id="Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects" data-mw-thread-id="h-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects-Connecting_to_the_database_replicas"><span data-mw-comment-start="" id="h-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects-Connecting_to_the_database_replicas"></span><span id="Connecting_to_the_database_replicas_from_other_Labs_instances"></span>Connecting to the wiki replicas from other Cloud VPS projects<span data-mw-comment-end="h-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects-Connecting_to_the_database_replicas"></span></h3></div> <p>The <code>*.{analytics,web}.db.svc.wikimedia.cloud</code> servers should be directly accessible from other Cloud VPS projects as well as Toolforge (these are provided in DNS), but there is no automatic creation of database credential files. The easiest way to get user credentials for use in another project is to <a href="/wiki/Help:Toolforge#Creating_a_new_Tool_account" title="Help:Toolforge">create a Toolforge tool account</a> and copy its credentials to your Cloud VPS instance. </p> <div class="mw-heading mw-heading3"><h3 id="Connecting_to_the_database_replicas_from_your_own_computer" data-mw-thread-id="h-Connecting_to_the_database_replicas_from_your_own_computer-Connecting_to_the_database_replicas"><span data-mw-comment-start="" id="h-Connecting_to_the_database_replicas_from_your_own_computer-Connecting_to_the_database_replicas"></span>Connecting to the database replicas from your own computer<span data-mw-comment-end="h-Connecting_to_the_database_replicas_from_your_own_computer-Connecting_to_the_database_replicas"></span></h3></div> <p>Since at the moment Wiki Replicas are not public (<a href="https://phabricator.wikimedia.org/T318191" class="extiw" title="phabricator:T318191">phabricator:T318191</a>), you can access the database replicas from your own computer by setting up an SSH tunnel. If you use MySQL Workbench, you can find a detailed description for that application <a href="#MySQL_Workbench">below</a>. </p><p>Tunneling is a built-in capability of ssh. It allows creating a listening TCP port on your local computer that will transparently forward all connections to a given host and port on the remote side of the ssh connection. The destination host and port do not need to be the host that you are connecting to with your ssh session, but they do need to be reachable from the remote host. </p><p>In the general case, need to add a port forwarding in your ssh tool. Windows 10 has OpenSSH included and the <code>ssh</code> command can be used. On older versions of Windows, you can use the tool <a href="https://en.wikipedia.org/wiki/PuTTY" class="extiw" title="w:PuTTY">PuTTY</a> by add in <i>Connection → SSH → Tunnels</i> the following settings (as shown in dialog box at right). </p> <figure typeof="mw:File/Thumb"><a href="/wiki/File:PuTTY_Tunnels_Config.jpg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/4/42/PuTTY_Tunnels_Config.jpg/400px-PuTTY_Tunnels_Config.jpg" decoding="async" width="400" height="353" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/4/42/PuTTY_Tunnels_Config.jpg/600px-PuTTY_Tunnels_Config.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/4/42/PuTTY_Tunnels_Config.jpg 2x" data-file-width="625" data-file-height="552"/></a><figcaption>PuTTY Tunnels Configuration</figcaption></figure> <p>In Linux or Windows 10, you can add the option <code>-L $LOCAL_PORT:$REMOTE_HOST:$REMOTE_PORT</code> to your <code>ssh</code> call, e. g.: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>ssh<span class="w"> </span>-L<span class="w"> </span><span class="m">3306</span>:enwiki.analytics.db.svc.wikimedia.cloud:3306<span class="w"> </span>yourusername@login.toolforge.org </pre></div> <p>This will set up a tunnel so that connections to port <b>3306</b> on your own computer will be relayed to the <b>enwiki.analytics.db.svc.wikimedia.cloud</b> database replica's MariaDB server on port <b>3306</b>. This tunnel will continue to work as long as the SSH session is open. </p><p>The <code>mariadb</code> command line to connect using the tunnel from the example above would look something like: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>mariadb<span class="w"> </span>--user<span class="o">=</span><span class="nv">$USER_FROM_REPLICA</span>.MY.CNF<span class="w"> </span>--host<span class="o">=</span><span class="m">127</span>.0.0.1<span class="w"> </span>--port<span class="o">=</span><span class="m">3306</span><span class="w"> </span>--password<span class="w"> </span>enwiki_p </pre></div> <p>The <b>user</b> and <b>password</b> values needed can be found in the <code>$HOME/replica.my.cnf</code> credentials file for your Toolforge user account or a tool that you have access to. </p><p>Note that you need to explicitly use the <code>127.0.0.1</code> IP address; using <code>localhost</code> instead will give an error as the client will try to connect over an <a href="https://en.wikipedia.org/wiki/Unix_domain_socket" class="extiw" title="w:Unix domain socket">Unix socket</a> which will not work. </p> <div class="mw-heading mw-heading4"><h4 id="SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases" data-mw-thread-id="h-SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases-Connecting_to_the_database_replicas_from_your_own_computer"><span data-mw-comment-start="" id="h-SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases-Connecting_to_the_database_replicas_from_your_own_computer"></span>SSH tunneling for local testing which makes use of Wiki Replica databases<span data-mw-comment-end="h-SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases-Connecting_to_the_database_replicas_from_your_own_computer"></span></h4></div> <p><span id="Steps_to_setup_SSH_tunneling_for_testing_a_tool_labs_application_which_makes_use_of_tool_labs_databases_on_your_own_computer"></span> </p> <ol><li>Setup SSH tunnels: <code>ssh -N yourusername@dev.toolforge.org -L 3306:enwiki.analytics.db.svc.wikimedia.cloud:3306</code> <ul><li><code>-N</code> prevents ssh from opening an interactive shell. This connection will only be useful for port forwarding.</li> <li>The first port is the listening port on your machine and the second one is on the remote server. 3306 is the default port for MySQL.</li> <li>For multiple database connections, add additional <code>-L $LOCAL_PORT:$REMOTE_HOST:$REMOTE_PORT</code> sections to the same command or open additional ssh connections.</li> <li>If you need to connect to more than one Wiki Replica database server, each database will need a different listening port on your machine (e.g. 3307, 3308, 3309, ...). Change the associated php/python connect command to send requests to that port instead of the default 3306.</li></ul></li> <li>(optional) Edit your <code>/etc/hosts</code> file to add something like <code>127.0.0.1 enwiki.analytics.db.svc.wikimedia.cloud</code> for each of the databases you're connecting to.</li> <li>You might need to copy over the replica.my.cnf file to your local machine for this to work.</li></ol> <div class="mw-heading mw-heading3"><h3 id="TLS_connection_failures" data-mw-thread-id="h-TLS_connection_failures-Connecting_to_the_database_replicas"><span data-mw-comment-start="" id="h-TLS_connection_failures-Connecting_to_the_database_replicas"></span>TLS connection failures<span data-mw-comment-end="h-TLS_connection_failures-Connecting_to_the_database_replicas"></span></h3></div> <style data-mw-deduplicate="TemplateStyles:r2199615">.mw-parser-output .tracked{border:1px solid var(--border-color-base,#a2a9b1);border-radius:.5em;background-color:var(--background-color-interactive,#eaecf0);background-image:linear-gradient(var(--background-color-interactive,#eaecf0),var(--background-color-interactive-subtle,#f8f9fa));color:var(--color-base,#202122);font-size:85%;text-align:center;margin-bottom:1em;width:12em;padding:0.5em}.mw-parser-output .tracked-status{color:var(--color-emphasized,#000);font-weight:bold;text-transform:uppercase}.mw-parser-output .tracked-status--resolved{color:var(--color-success,#14866d)}.mw-parser-output .tracked-status--critical{color:var(--color-error,#d73333);font-size:1.5em}</style> <div style="float:right; clear:right; margin-left:1em;" class="plainlinks tracked mw-trackedTemplate">Tracked in <a href="https://phabricator.wikimedia.org/" class="extiw" title="phabricator:">Phabricator</a><br/><b><a href="https://phabricator.wikimedia.org/T182892" class="extiw" title="phabricator:T182892"><span class="trakfab-T182892">Task T182892</span></a></b> <span class="tracked-status tracked-status--resolved">Resolved</span></div> <p>Some client libraries may attempt to enable <a href="https://en.wikipedia.org/wiki/Transport_Layer_Security" class="extiw" title="w:Transport Layer Security">TLS</a> encryption when connecting to the Wiki Replica or ToolsDB databases. Depending on the backing server's configuration, this may either fail silently because TLS is not supported at all, or it may fail with authentication or decryption errors because TLS is partially enabled. In this second case, the problem is caused by MariaDB servers which <i>do</i> support TLS encryption but are using self-signed certificates which are not available to the client and do not match the service names used for connections from Cloud Services hosts. </p><p>The "fix" for these failures is to configure your client to avoid TLS encryption. How to do this will vary based on the client libraries in use, but should be something that you can find an answer for by searching the Internet/Stack Overflow/library documentation. </p> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Databases" data-mw-thread-id="h-Databases"><span data-mw-comment-start="" id="h-Databases"></span>Databases<span data-mw-comment-end="h-Databases"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Databases","replies":["h-Replica_database_schema_(tables_and_indexes)-Databases","h-Metadata_database-Databases","h-Identifying_lag-Databases","h-User_databases-Databases"]}}--></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2199624"> <div class="rellink mw-tpl-rellink">See also: <a href="/wiki/Help:MySQL_queries" class="mw-redirect" title="Help:MySQL queries">Help:MySQL queries</a></div> <div class="mw-heading mw-heading3"><h3 id="Replica_database_schema_(tables_and_indexes)" data-mw-thread-id="h-Replica_database_schema_(tables_and_indexes)-Databases"><span id="Replica_database_schema_.28tables_and_indexes.29"></span><span data-mw-comment-start="" id="h-Replica_database_schema_(tables_and_indexes)-Databases"></span>Replica database schema (tables and indexes)<span data-mw-comment-end="h-Replica_database_schema_(tables_and_indexes)-Databases"></span></h3></div> <p>The database replicas for the various Wikimedia projects follow the standard MediaWiki database schema <a href="https://www.mediawiki.org/wiki/Manual:Database_layout" class="extiw" title="mw:Manual:Database layout">described on mediawiki.org</a> and in <a href="https://phabricator.wikimedia.org/diffusion/MW/browse/master/sql/mysql/tables-generated.sql" class="extiw" title="phab:diffusion/MW/browse/master/sql/mysql/tables-generated.sql">the MediaWiki git repository</a>. </p><p>Many of the indexes on these tables are actually compound indexes designed to optimize the runtime performance of the MediaWiki software rather than to be convenient for ad hoc queries. For example, a naive query by <code>page_title</code> such at <code>SELECT * FROM page WHERE page_title = 'NOFX';</code> will be slow because the index which includes <code>page_title</code> is a compound index with <code>page_namespace</code>. Adding <code>page_namespace</code> to the <code>WHERE</code> clause will improve the query speed dramatically: <code>SELECT * FROM page WHERE page_namespace = 0 AND page_title = 'NOFX';</code> </p> <div class="mw-heading mw-heading4"><h4 id="Stability_of_the_mediawiki_database_schema" data-mw-thread-id="h-Stability_of_the_mediawiki_database_schema-Replica_database_schema_(tables_and_indexes)"><span data-mw-comment-start="" id="h-Stability_of_the_mediawiki_database_schema-Replica_database_schema_(tables_and_indexes)"></span>Stability of the mediawiki database schema<span data-mw-comment-end="h-Stability_of_the_mediawiki_database_schema-Replica_database_schema_(tables_and_indexes)"></span></h4></div> <p><a href="https://phabricator.wikimedia.org/diffusion/MW/browse/master/sql/mysql/tables-generated.sql" class="extiw" title="phab:diffusion/MW/browse/master/sql/mysql/tables-generated.sql">sql/mysql/tables-generated.sql</a> shows the HEAD of the mediawiki changes. Extra tables may be available due to additional extensions setup in production. Also some tables may have been redacted or filtered for containing private data such as the user passwords or private ip addresses. Aside from that, while we try to synchronize production with development HEAD, changes to the database structure may be applied in advance (or more commonly) lag behind its publication. The reason for this is that schema changes are being continuously applied to production databases, and due to the amout of data, it may take a few hours to a few months (in the case of more complex cases) to be finalized. </p><p>Core tables, such as revision, page, user, recentchanges rarely change, but <b>cloud maintainers cannot guarantee they will never change</b>, as they have to follow the production changes. While we are happy for people to setup scripts and tools on top of the database copies (wikireplicas) expect the schema to change every now and then. If you cannot do small tweaks from time to time to adapt to the latest schema changes, using the API instead of the database internals is suggested, as <b>API changes have more guarantees of stability and a proper lifecycle and deprecation policy. That is not true for mediawiki database internals</b>, although compatibility views can sometimes be setup to require only minimal changes. </p> <div class="mw-heading mw-heading4"><h4 id="Tables_for_revision_or_logging_queries_involving_user_names_and_IDs" data-mw-thread-id="h-Tables_for_revision_or_logging_queries_involving_user_names_and_IDs-Replica_database_schema_(tables_and_indexes)"><span data-mw-comment-start="" id="h-Tables_for_revision_or_logging_queries_involving_user_names_and_IDs-Replica_database_schema_(tables_and_indexes)"></span>Tables for revision or logging queries involving user names and IDs<span data-mw-comment-end="h-Tables_for_revision_or_logging_queries_involving_user_names_and_IDs-Replica_database_schema_(tables_and_indexes)"></span></h4></div> <p>The <code>revision</code> and <code>logging</code> tables do not have indexes on user columns. <a class="external text" href="https://lists.wikimedia.org/pipermail/labs-l/2013-September/001607.html">In an email</a>, one of the system administrators pointed out that this is because "those values are conditionally nulled when supressed" (see also <a href="https://phabricator.wikimedia.org/T68786" class="extiw" title="phab:T68786">phab:T68786</a> for some more detail). One has to instead use the corresponding <code>revision_userindex</code> or <code>logging_userindex</code> for these types of queries. On those views, rows where the column would have otherwise been nulled are elided; this allows the indexes to be usable. </p><p>Example query that will use the appropriate index (in this case on the <code>rev_actor</code> column) </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">rev_id</span><span class="p">,</span><span class="w"> </span><span class="n">rev_timestamp</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">revision_userindex</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">rev_actor</span><span class="o">=</span><span class="mi">1234</span><span class="p">;</span> </pre></div> <p>Example query that <i>fails</i> to use an index because the table doesn't have them: </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">rev_id</span><span class="p">,</span><span class="w"> </span><span class="n">rev_timestamp</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">revision</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">rev_actor</span><span class="o">=</span><span class="mi">1234</span><span class="p">;</span> </pre></div> <p>You should use the indexes so queries will go faster (performance). </p> <div class="mw-heading mw-heading4"><h4 id="Redacted_tables" data-mw-thread-id="h-Redacted_tables-Replica_database_schema_(tables_and_indexes)"><span data-mw-comment-start="" id="h-Redacted_tables-Replica_database_schema_(tables_and_indexes)"></span>Redacted tables<span data-mw-comment-end="h-Redacted_tables-Replica_database_schema_(tables_and_indexes)"></span></h4></div> <p>The majority of the <a href="https://www.mediawiki.org/wiki/Manual:User_properties_table" class="extiw" title="mw:Manual:User properties table">user_properties table</a> has been deemed sensitive and removed from the Wiki Replica databases. Only the <code>disableemail</code>, <code>fancysig</code>, <code>gender</code>, and <code>nickname</code> properties are available. </p> <div class="mw-heading mw-heading4"><h4 id="Unavailable_tables" data-mw-thread-id="h-Unavailable_tables-Replica_database_schema_(tables_and_indexes)"><span data-mw-comment-start="" id="h-Unavailable_tables-Replica_database_schema_(tables_and_indexes)"></span><span id="Unused_tables"></span>Unavailable tables<span data-mw-comment-end="h-Unavailable_tables-Replica_database_schema_(tables_and_indexes)"></span></h4></div> <p>Some of the standard MediaWiki tables that are in use on Wikimedia wikis are not available. The following tables are missing or empty: </p> <ul><li><code>interwiki</code> (<a href="https://phabricator.wikimedia.org/T103589" class="extiw" title="phab:T103589">T103589</a>)</li> <li><a href="https://www.mediawiki.org/wiki/Manual:text_table" class="extiw" title="mw:Manual:text table"><code>text</code> table</a> (<a href="https://www.mediawiki.org/wiki/Manual:MediaWiki_architecture#Database_and_text_storage" class="extiw" title="mw:Manual:MediaWiki architecture">mw:Manual:MediaWiki architecture#Database and text storage</a>): Users can use the <a href="https://www.mediawiki.org/wiki/API:Query#Sample_query" class="extiw" title="mw:API:Query">API</a>, <a href="/wiki/Help:Toolforge/Dumps" class="mw-redirect" title="Help:Toolforge/Dumps">dumps</a>, or <a href="/wiki/Help:CirrusSearch_elasticsearch_replicas" title="Help:CirrusSearch elasticsearch replicas">CirrusSearch replicas</a> to access page contents.</li></ul> <div class="mw-heading mw-heading3"><h3 id="Metadata_database" data-mw-thread-id="h-Metadata_database-Databases"><span data-mw-comment-start="" id="h-Metadata_database-Databases"></span>Metadata database<span data-mw-comment-end="h-Metadata_database-Databases"></span></h3></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2199615"> <div style="float:right; clear:right; margin-left:1em;" class="plainlinks tracked mw-trackedTemplate">Tracked in <a href="https://phabricator.wikimedia.org/" class="extiw" title="phabricator:">Phabricator</a><br/><b><a href="https://phabricator.wikimedia.org/T50626" class="extiw" title="phabricator:T50626"><span class="trakfab-T50626">Task T50626</span></a></b> <span class="tracked-status tracked-status--resolved">Resolved</span></div> <p>There is a table with automatically maintained meta information about the replicated databases: <code>meta_p.wiki</code>. See <a href="https://iw.toolforge.org/db-names" class="extiw" title="toolforge:db-names">toolforge:db-names</a> for a web-based list. </p><p>The database host containing the <code>meta_p</code> database is: <code>meta.analytics.db.svc.wikimedia.cloud</code>. </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">MariaDB</span><span class="w"> </span><span class="p">[</span><span class="n">meta_p</span><span class="p">]</span><span class="o">></span><span class="w"> </span><span class="k">DESCRIBE</span><span class="w"> </span><span class="n">wiki</span><span class="p">;</span> </pre></div> <pre>+------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+-------+ | dbname | varchar(32) | NO | PRI | NULL | | | lang | varchar(12) | NO | | en | | | name | text | YES | | NULL | | | family | text | YES | | NULL | | | url | text | YES | | NULL | | | size | decimal(1,0) | NO | | 1 | | | slice | text | NO | | NULL | | | is_closed | decimal(1,0) | NO | | 0 | | | has_echo | decimal(1,0) | NO | | 0 | | | has_flaggedrevs | decimal(1,0) | NO | | 0 | | | has_visualeditor | decimal(1,0) | NO | | 0 | | | has_wikidata | decimal(1,0) | NO | | 0 | | | is_sensitive | decimal(1,0) | NO | | 0 | | +------------------+--------------+------+-----+---------+-------+ </pre> <p>Example data: </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">MariaDB</span><span class="w"> </span><span class="p">[</span><span class="n">meta_p</span><span class="p">]</span><span class="o">></span><span class="w"> </span><span class="k">select</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="n">wiki</span><span class="w"> </span><span class="k">limit</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="err">\</span><span class="k">G</span> </pre></div> <pre>*************************** 1. row *************************** dbname: aawiki lang: aa name: Wikipedia family: wikipedia url: https://aa.wikipedia.org size: 1 slice: s3.labsdb is_closed: 1 has_echo: 1 has_flaggedrevs: 0 has_visualeditor: 1 has_wikidata: 1 is_sensitive: 0 </pre> <div class="mw-heading mw-heading3"><h3 id="Identifying_lag" data-mw-thread-id="h-Identifying_lag-Databases"><span data-mw-comment-start="" id="h-Identifying_lag-Databases"></span>Identifying lag<span data-mw-comment-end="h-Identifying_lag-Databases"></span></h3></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-warn">Extended replication lag (on the order of multiple days) can be an expected and unavoidable side effect of some types of production database maintenance (e.g. schema changes). When this cause is confirmed, expect wiki replicas to catch up automatically once the maintenance finishes.</div> <p>If there is a network/Wiki Replica db infrastructure problem, production problem, maintenance (scheduled or unscheduled), excessive load or production or user's queries blocking the replication process, the Wiki Replicas can "lag" behind the production databases. </p><p>To identify lag, see <a href="https://iw.toolforge.org/replag/" class="extiw" title="toolforge:replag/">the replag tool</a> or execute yourself on the database host you are connected to: </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="p">(</span><span class="n">u3518</span><span class="o">@</span><span class="n">enwiki</span><span class="p">.</span><span class="n">analytics</span><span class="p">.</span><span class="n">db</span><span class="p">.</span><span class="n">svc</span><span class="p">.</span><span class="n">wikimedia</span><span class="p">.</span><span class="n">cloud</span><span class="p">)</span><span class="w"> </span><span class="p">[</span><span class="n">heartbeat_p</span><span class="p">]</span><span class="o">></span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">heartbeat</span><span class="p">;</span> </pre></div> <pre>+-------+----------------------------+--------+ | shard | last_updated | lag | +-------+----------------------------+--------+ | s1 | 2018-01-09T22:47:05.001180 | 0.0000 | | s2 | 2018-01-09T22:47:05.001190 | 0.0000 | | s3 | 2018-01-09T22:47:05.001290 | 0.0000 | | s4 | 2018-01-09T22:47:05.000570 | 0.0000 | | s5 | 2018-01-09T22:47:05.000670 | 0.0000 | | s6 | 2018-01-09T22:47:05.000760 | 0.0000 | | s7 | 2018-01-09T22:47:05.000690 | 0.0000 | | s8 | 2018-01-09T22:47:05.000600 | 0.0000 | +-------+----------------------------+--------+ 8 rows in set (0.00 sec) </pre> <p>This table is based on the tool <a rel="nofollow" class="external text" href="https://www.percona.com/doc/percona-toolkit/2.2/pt-heartbeat.html">pt-heartbeat</a>, not on SHOW MASTER STATUS, producing very accurate results, even if replication is broken, and directly comparing it to the original master, and not the replicas's direct master. </p> <ul><li><b>shard</b>: s1-8. Each of the production masters. The wiki distribution can be seen at: <a class="external free" href="https://noc.wikimedia.org/db.php">https://noc.wikimedia.org/db.php</a></li> <li><b>last_updated</b>: Every 1 second, a row in the master is written with the date local to the master. Here you have its value, once replicated. As it is updated every 1 second, it has a measuring error of [0, 1+] seconds.</li> <li><b>lag</b>: The difference between the current date and the last_updated column (<code>timestampdiff(MICROSECOND,`heartbeat`.`heartbeat`.`ts`,utc_timestamp())/1000000.0</code>). Again note that updates to this table only happen every second (it can vary on production), so most decimals are meaningless.</li></ul> <p>To directly query the replication lag for a particular wiki, use requests like: </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">MariaDB</span><span class="w"> </span><span class="p">[</span><span class="n">fawiki_p</span><span class="p">]</span><span class="o">></span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="n">lag</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">heartbeat_p</span><span class="p">.</span><span class="n">heartbeat</span><span class="w"> </span><span class="k">JOIN</span><span class="w"> </span><span class="n">meta_p</span><span class="p">.</span><span class="n">wiki</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">shard</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">SUBSTRING_INDEX</span><span class="p">(</span><span class="n">slice</span><span class="p">,</span><span class="w"> </span><span class="ss">"."</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">dbname</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'fawiki'</span><span class="p">;</span> <span class="o">+</span><span class="c1">------+</span> <span class="o">|</span><span class="w"> </span><span class="n">lag</span><span class="w"> </span><span class="o">|</span> <span class="o">+</span><span class="c1">------+</span> <span class="o">|</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="o">|</span> <span class="o">+</span><span class="c1">------+</span> <span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="k">set</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">09</span><span class="w"> </span><span class="n">sec</span><span class="p">)</span> </pre></div> <p>Please note that some seconds or a few minutes of lag is considered normal, due to the filtering process and the hops done before reaching the public hosts. </p> <div class="mw-heading mw-heading3"><h3 id="User_databases" data-mw-thread-id="h-User_databases-Databases"><span data-mw-comment-start="" id="h-User_databases-Databases"></span>User databases<span data-mw-comment-end="h-User_databases-Databases"></span></h3></div> <p>User-created databases can be created on a shared server: <code>tools.db.svc.wikimedia.cloud</code>. Database names must start with the name of the credential user followed by <i>two underscores</i> and then the name of the database: <b><credentialUser>__<DBName></b> (e.g. "s51234__mydb"). </p><p>The credential user is not your user name. It can be found in your $HOME/replica.my.cnf file. The name of the credential user looks something like 'u1234' for a user and 's51234' for a tool account. You can also find the name of the credential user using a live database connection: </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">SUBSTRING_INDEX</span><span class="p">(</span><span class="k">CURRENT_USER</span><span class="p">(),</span><span class="w"> </span><span class="s1">'@'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span> </pre></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-info"><span id="Trove"></span>If your tool needs more than <b>25GB of storage</b>, open connection limits that ToolsDB cannot support, or a Postgres runtime, <a href="/wiki/Help:Trove_database_user_guide" title="Help:Trove database user guide">Trove databases</a> may be a better fit. ToolsDB is a shared resource that must impose connection and size limitations in exchange for zero administration requirements. Using Trove removes those limitations, but requires a small amount of administration. Tools can request the ability to create Trove databases via a <a href="https://phabricator.wikimedia.org/project/view/4834/" class="extiw" title="phab:project/view/4834/">Toolforge quota-request</a> task.</div> <div class="mw-heading mw-heading4"><h4 id="Privileges_on_the_database" data-mw-thread-id="h-Privileges_on_the_database-User_databases"><span data-mw-comment-start="" id="h-Privileges_on_the_database-User_databases"></span>Privileges on the database<span data-mw-comment-end="h-Privileges_on_the_database-User_databases"></span></h4></div> <p>Users have all privileges and have access to all grant options on their databases. <b>Database names ending with <code>_p</code> are granted read access for everyone.</b> Please create a <a class="external text" href="https://phabricator.wikimedia.org/maniphest/task/create/">ticket</a> if you need more fine-grained permissions, like sharing a database only between 2 users, or other special permissions. </p> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-info">Public databases in ToolsDB (the ones with a name ending in <code>_p</code>) can also be accessed from <a href="/wiki/Quarry" title="Quarry">Quarry</a> and <a href="/wiki/Superset" title="Superset">Superset</a>.</div> <div class="mw-heading mw-heading4"><h4 id="Steps_to_create_a_user_database" data-mw-thread-id="h-Steps_to_create_a_user_database-User_databases"><span data-mw-comment-start="" id="h-Steps_to_create_a_user_database-User_databases"></span>Steps to create a user database<span data-mw-comment-end="h-Steps_to_create_a_user_database-User_databases"></span></h4></div> <p>To create a database on <code>tools.db.svc.wikimedia.cloud</code>: </p> <ol><li>Become your tool account. <pre>maintainer@tools-login:~$ become toolaccount</pre></li> <li>Connect to tools.db.svc.wikimedia.cloud with the replica.my.cnf credentials: <pre>mariadb --defaults-file=$HOME/replica.my.cnf -h tools.db.svc.wikimedia.cloud</pre> You could also just type: <pre>sql tools</pre></li> <li>In the MariaDB console, create a new database (where CREDENTIALUSER is your credentials user, which can be found in your ~/replica.my.cnf file, and DBNAME the name you want to give to your database. Note that there are 2 underscores between CREDENTIALUSER and DBNAME): <pre>MariaDB [(none)]> CREATE DATABASE CREDENTIALUSER__DBNAME;</pre></li></ol> <p>You can then connect to your database using: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>mariadb<span class="w"> </span>--defaults-file<span class="o">=</span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span>-h<span class="w"> </span>tools.db.svc.wikimedia.cloud<span class="w"> </span>CREDENTIALUSER__DBNAME </pre></div> <p>Or: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>sql<span class="w"> </span>tools </pre></div> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">MariaDB</span><span class="w"> </span><span class="p">[(</span><span class="k">none</span><span class="p">)]</span><span class="o">></span><span class="w"> </span><span class="n">USE</span><span class="w"> </span><span class="n">CREDENTIALUSER__DBNAME</span><span class="p">;</span> </pre></div> <p><b>Example</b> </p><p>Assuming that your tool account is called "mytool", this is what it would look like: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="gp">$ </span>maintainer@tools-login:~$<span class="w"> </span>become<span class="w"> </span>mytool <span class="gp">$ </span>tools.mytool@tools-login:~$<span class="w"> </span>mariadb<span class="w"> </span>--defaults-file<span class="o">=</span><span class="nv">$HOME</span>/replica.my.cnf<span class="w"> </span>-h<span class="w"> </span>tools.db.svc.wikimedia.cloud </pre></div> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">MariaDB</span><span class="w"> </span><span class="p">[(</span><span class="k">none</span><span class="p">)]</span><span class="o">></span><span class="w"> </span><span class="k">select</span><span class="w"> </span><span class="n">substring_index</span><span class="p">(</span><span class="k">current_user</span><span class="p">(),</span><span class="w"> </span><span class="s1">'@'</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">uname</span><span class="p">;</span> <span class="o">+</span><span class="c1">---------------+</span> <span class="o">|</span><span class="w"> </span><span class="n">uname</span><span class="w"> </span><span class="o">|</span> <span class="o">+</span><span class="c1">---------------+</span> <span class="o">|</span><span class="w"> </span><span class="n">u123something</span><span class="w"> </span><span class="o">|</span> <span class="o">+</span><span class="c1">---------------+</span> <span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="k">set</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">00</span><span class="w"> </span><span class="n">sec</span><span class="p">)</span> <span class="n">MariaDB</span><span class="w"> </span><span class="p">[(</span><span class="k">none</span><span class="p">)]</span><span class="o">></span><span class="w"> </span><span class="k">create</span><span class="w"> </span><span class="k">database</span><span class="w"> </span><span class="n">u123something__wiki</span><span class="p">;</span> </pre></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-warn"><b>Caution:</b> The legacy <code>tools-db</code> service name was deprecated in September 2017 and removed in May 2019. Use <i>tools.db.svc.wikimedia.cloud</i> instead.</div><p><b>Note</b>: Some projects like <code>python-Django</code> can throw an exception like <code>MySQLdb._exceptions.OperationalError: (1709, 'Index column size too large. The maximum column size is 767 bytes.')</code> when migrated using the setup above. This can be fixed by altering the database charset to <code>utf-8</code>in most cases. To avoid this, create the database using the following command instead to specify the charset: </p><div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">MariaDB</span><span class="w"> </span><span class="p">[(</span><span class="k">none</span><span class="p">)]</span><span class="o">></span><span class="w"> </span><span class="k">CREATE</span><span class="w"> </span><span class="k">DATABASE</span><span class="w"> </span><span class="n">CREDENTIALUSER__DBNAME</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="n">utf8</span><span class="p">;</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="ToolsDB_read-only_replica_host" data-mw-thread-id="h-ToolsDB_read-only_replica_host-User_databases"><span data-mw-comment-start="" id="h-ToolsDB_read-only_replica_host-User_databases"></span>ToolsDB read-only replica host<span data-mw-comment-end="h-ToolsDB_read-only_replica_host-User_databases"></span></h4></div> <p>We maintain two copies of the ToolsDB database, using a MariaDB primary-replica setup. </p><p>The read-only replica host can be accessed using the same credentials and the following hostname: <code>tools-readonly.db.svc.wikimedia.cloud</code> </p><p>Using the read-only replica host is recommended if you have to run queries that take a long time to complete, as in this way you will reduce the load on the primary host. </p><p>Please note that the replica host can sometimes lag behind the primary host, but we are doing our best to keep this lag at a minimum. </p> <div class="mw-heading mw-heading4"><h4 id="ToolsDB_Backups" data-mw-thread-id="h-ToolsDB_Backups-User_databases"><span data-mw-comment-start="" id="h-ToolsDB_Backups-User_databases"></span>ToolsDB Backups<span data-mw-comment-end="h-ToolsDB_Backups-User_databases"></span></h4></div> <p>We don't do offline backups of any of the databases in ToolsDB. ToolsDB users can backup their data using <a rel="nofollow" class="external text" href="https://mariadb.com/kb/en/mariadb-dumpmysqldump/">mariadb-dump</a> (included in the <code>mariadb</code> <a href="/wiki/Help:Toolforge/Jobs_framework#Choosing_the_execution_runtime" title="Help:Toolforge/Jobs framework">image</a>) if necessary: </p> <div class="mw-highlight mw-highlight-lang-shell-session mw-content-ltr" dir="ltr"><pre><span></span><span class="go">:# use umask to make the dump private (use unless the database is public)</span> <span class="gp">$ </span>toolforge<span class="w"> </span><span class="nb">jobs</span><span class="w"> </span>run<span class="w"> </span>--command<span class="w"> </span><span class="s2">"umask o-r; ( mariadb-dump --defaults-file=~/replica.my.cnf --host=tools-readonly.db.svc.wikimedia.cloud credentialUser__DBName > ~/DBname-</span><span class="k">$(</span>date<span class="w"> </span>-I<span class="k">)</span><span class="s2">.sql )"</span><span class="w"> </span>--image<span class="w"> </span>mariadb<span class="w"> </span>backup </pre></div> <p>Note that we don't recommend storing backups permanently on NFS (<code>/data/project</code>, <code>/home</code>, or <code>/data/scratch</code> on Toolforge) or on any other Cloud VPS hosted drive. True backups should be kept offsite. </p> <div class="mw-heading mw-heading4"><h4 id="ToolsDB_Caveats" data-mw-thread-id="h-ToolsDB_Caveats-User_databases"><span data-mw-comment-start="" id="h-ToolsDB_Caveats-User_databases"></span>ToolsDB Caveats<span data-mw-comment-end="h-ToolsDB_Caveats-User_databases"></span></h4></div> <p>The Toolsforge team tries to keep ToolsDB configurations as close to MariaDB defaults as possible. This can lead to surprising behaviors, such as: </p> <ol><li>Transactions not rolled back on query timeouts, which can be common during high load on a shared database (see <a href="https://phabricator.wikimedia.org/T251030" class="extiw" title="phab:T251030">this issue</a>)</li></ol> <p>If you encounter an issue, feel free to add it above. </p> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Query_Limits" data-mw-thread-id="h-Query_Limits"><span data-mw-comment-start="" id="h-Query_Limits"></span>Query Limits<span data-mw-comment-end="h-Query_Limits"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Query_Limits","replies":[]}}--></div> <p>One can use <a rel="nofollow" class="external text" href="https://mariadb.com/kb/en/library/server-system-variables/#max_statement_time">max_statement_time</a> (unit is seconds, it allows decimals): </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="k">SET</span><span class="w"> </span><span class="n">max_statement_time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">300</span><span class="p">;</span> </pre></div> <p>And all subsequent queries on the same connection will be killed if they run for longer than the given time. </p><p>For example: </p> <div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="n">mariadb</span><span class="p">[(</span><span class="k">none</span><span class="p">)]</span><span class="o">></span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="n">max_statement_time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span> <span class="n">Query</span><span class="w"> </span><span class="n">OK</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="k">rows</span><span class="w"> </span><span class="n">affected</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">00</span><span class="w"> </span><span class="n">sec</span><span class="p">)</span> <span class="n">mariadb</span><span class="p">[(</span><span class="k">none</span><span class="p">)]</span><span class="o">></span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="n">sleep</span><span class="p">(</span><span class="mi">20</span><span class="p">);</span> <span class="o">+</span><span class="c1">-----------+</span> <span class="o">|</span><span class="w"> </span><span class="n">sleep</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span><span class="w"> </span><span class="o">|</span> <span class="o">+</span><span class="c1">-----------+</span> <span class="o">|</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">|</span> <span class="o">+</span><span class="c1">-----------+</span> <span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="k">set</span><span class="w"> </span><span class="p">(</span><span class="mi">10</span><span class="p">.</span><span class="mi">00</span><span class="w"> </span><span class="n">sec</span><span class="p">)</span> </pre></div> <p>It works on <a href="https://quarry.wmcloud.org/query/22003" class="extiw" title="quarry:query/22003">Quarry</a>, too! </p><p> You can also set limits with a single SQL query. For example:</p><div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span></span><span class="k">SET</span><span class="w"> </span><span class="k">STATEMENT</span><span class="w"> </span><span class="n">max_statement_time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">300</span><span class="w"> </span><span class="k">FOR</span> <span class="k">SELECT</span><span class="w"> </span><span class="k">COUNT</span><span class="p">(</span><span class="n">rev_id</span><span class="p">)</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">revision_userindex</span> <span class="k">INNER</span><span class="w"> </span><span class="k">JOIN</span><span class="w"> </span><span class="n">actor</span> <span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">rev_actor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">actor_id</span> <span class="k">WHERE</span><span class="w"> </span><span class="n">actor_name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'Jimbo Wales'</span> </pre></div> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Example_queries" data-mw-thread-id="h-Example_queries"><span data-mw-comment-start="" id="h-Example_queries"></span>Example queries<span data-mw-comment-end="h-Example_queries"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Example_queries","replies":[]}}--></div> <p>See <a href="/wiki/Help:MySQL_queries" class="mw-redirect" title="Help:MySQL queries">Help:MySQL queries</a>. Add yours! </p> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Connecting_with..." data-mw-thread-id="h-Connecting_with..."><span data-mw-comment-start="" id="h-Connecting_with..."></span>Connecting with...<span data-mw-comment-end="h-Connecting_with..."></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Connecting_with...","replies":["h-MySQL_Workbench-Connecting_with..."]}}--></div> <div class="mw-heading mw-heading3"><h3 id="MySQL_Workbench" data-mw-thread-id="h-MySQL_Workbench-Connecting_with..."><span data-mw-comment-start="" id="h-MySQL_Workbench-Connecting_with..."></span>MySQL Workbench<span data-mw-comment-end="h-MySQL_Workbench-Connecting_with..."></span></h3></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r2211903"><div role="note" class="note note-error">If you are using an ed25519 key, with a passcode, you might have issues configuring this. See the <a rel="nofollow" class="external text" href="https://bugs.mysql.com/bug.php?id=94620">MySQL bug</a>. Consider <a href="#SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases">establishing a separate SSH tunnel</a> outside of MySQL Workbench, then using MySQL Workbench with connection method "Standard (TCP/IP)" and hostname 127.0.0.1, the other credentials remaining unchanged.</div> <figure typeof="mw:File/Thumb"><a href="/wiki/File:Toolforge_DB_example.png" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/8/81/Toolforge_DB_example.png/240px-Toolforge_DB_example.png" decoding="async" width="240" height="150" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/8/81/Toolforge_DB_example.png/360px-Toolforge_DB_example.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/8/81/Toolforge_DB_example.png/480px-Toolforge_DB_example.png 2x" data-file-width="1600" data-file-height="1000"/></a><figcaption>Example configuration of MySQL Workbench for Toolforge</figcaption></figure> <p>You can connect to databases on Toolforge with <a rel="nofollow" class="external text" href="http://www.mysql.com/products/workbench/">MySQL Workbench</a> (or similar client applications) via an SSH tunnel. </p><p>Instructions for connecting via MySQL Workbench are as follows: </p> <ol><li>Launch MySQL Workbench on your local machine.</li> <li>Click the plus icon next to "MySQL Connections" in the Workbench window (or choose "Manage Connections..." from the Database menu and click the "new" button).</li> <li>Set Connection Method to "Standard TCP/IP over SSH"</li> <li>Set the following connection parameters: <ul><li>SSH Hostname: login.toolforge.org</li> <li>SSH Username: <your Toolforge shell username></li> <li>SSH Key File: <your Toolforge SSH private key file><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup></li> <li>SSH Password: password/passphrase of your private key (if set) - <u>not</u> your wiki login password.</li> <li>MySQL Hostname: enwiki.analytics.db.svc.wikimedia.cloud (or whatever server your database lives on)</li> <li>MySQL Server Port: 3306</li> <li>Username: <your Toolforge MariaDB user name (from $HOME/replica.my.cnf)></li> <li>Password: <your Toolforge MariaDB password (from $HOME/replica.my.cnf)></li> <li>Default Schema: <name of the database, e.g. enwiki_p></li></ul></li> <li>Click "OK"</li></ol> <p>Replica-db hostnames can be found in /etc/hosts. Bear in mind to add the _p suffix if setting a default schema for replica databases. e.g: enwiki_p. </p><p><span typeof="mw:File"><a href="/wiki/File:Ambox_notice.png" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Ambox_notice.png/20px-Ambox_notice.png" decoding="async" width="20" height="20" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Ambox_notice.png/30px-Ambox_notice.png 1.5x, //upload.wikimedia.org/wikipedia/commons/c/c8/Ambox_notice.png 2x" data-file-width="40" data-file-height="40"/></a></span> If you are using SSH keys generated with PuTTYgen (Windows users), you need to convert your private key to the 'OpenSSH' format. Load your private key in PuTTYgen, then click Conversions » Export OpenSSH key. Use this file as SSH Key File above. </p><p><span typeof="mw:File"><a href="/wiki/File:Ambox_notice.png" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Ambox_notice.png/20px-Ambox_notice.png" decoding="async" width="20" height="20" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Ambox_notice.png/30px-Ambox_notice.png 1.5x, //upload.wikimedia.org/wikipedia/commons/c/c8/Ambox_notice.png 2x" data-file-width="40" data-file-height="40"/></a></span> If you are getting errors with SSL, you can try disabling it. From the menu bar: Database -> select your connection -> SSL -> Change "Use SSL" to "No". </p> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Code_samples_for_common_languages" data-mw-thread-id="h-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Code_samples_for_common_languages"></span>Code samples for common languages<span data-mw-comment-end="h-Code_samples_for_common_languages"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Code_samples_for_common_languages","replies":["h-Bash-Code_samples_for_common_languages","h-C-Code_samples_for_common_languages","h-Perl-Code_samples_for_common_languages","h-Python-Code_samples_for_common_languages","h-Python:_Django-Code_samples_for_common_languages","h-PHP_(using_PDO)-Code_samples_for_common_languages","h-PHP_(using_MySQLi)-Code_samples_for_common_languages","h-Java-Code_samples_for_common_languages","h-Node.js-Code_samples_for_common_languages"]}}--></div> <dl><dd><i>Copied with edits from <a href="https://www.mediawiki.org/wiki/Toolserver:Database_access#Program_access" class="extiw" title="mw:Toolserver:Database access">mw:Toolserver:Database access#Program access</a></i> (not all tested, use with caution!)</dd></dl> <p>In most programming languages, it will be sufficient to tell MariaDB to use the database credentials found in <tt>$HOME/.my.cnf</tt> assuming that you have created a symlink from <tt>$HOME/.my.cnf</tt> to <tt>$HOME/replica.my.cnf</tt>. </p><p>Below are various examples in a few common programming languages. </p> <div class="mw-heading mw-heading3"><h3 id="Bash" data-mw-thread-id="h-Bash-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Bash-Code_samples_for_common_languages"></span>Bash<span data-mw-comment-end="h-Bash-Code_samples_for_common_languages"></span></h3></div> <div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span></span>--<span class="w"> </span><span class="m">2</span>><span class="w"> </span>/dev/null<span class="p">;</span><span class="w"> </span>date<span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s1">'</span> <span class="s1">/* Bash/SQL compatible test structure</span> <span class="s1"> *</span> <span class="s1"> * Run time: ? <SLOW_OK></span> <span class="s1"> */</span> <span class="s1">SELECT 1</span> <span class="s1">;-- '</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>mariadb<span class="w"> </span>-ch<span class="w"> </span>tools.db.svc.wikimedia.cloud<span class="w"> </span>enwiki_p<span class="w"> </span>><span class="w"> </span>~/query_results-enwiki<span class="p">;</span><span class="w"> </span>date<span class="p">;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="C" data-mw-thread-id="h-C-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-C-Code_samples_for_common_languages"></span>C<span data-mw-comment-end="h-C-Code_samples_for_common_languages"></span></h3></div> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><my_global.h></span> <span class="cp">#include</span><span class="w"> </span><span class="cpf"><mysql.h></span> <span class="p">...</span> <span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">host</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"tools.db.svc.wikimedia.cloud"</span><span class="p">;</span> <span class="w"> </span><span class="n">MYSQL</span><span class="w"> </span><span class="o">*</span><span class="n">conn</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mysql_init</span><span class="p">(</span><span class="nb">NULL</span><span class="p">);</span> <span class="w"> </span><span class="n">mysql_options</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span><span class="w"> </span><span class="n">MYSQL_READ_DEFAULT_GROUP</span><span class="p">,</span><span class="w"> </span><span class="s">"client"</span><span class="p">);</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">mysql_real_connect</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span><span class="w"> </span><span class="n">host</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"Error %u: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">mysql_errno</span><span class="p">(</span><span class="n">conn</span><span class="p">),</span><span class="w"> </span><span class="n">mysql_error</span><span class="p">(</span><span class="n">conn</span><span class="p">));</span> <span class="w"> </span><span class="p">...</span> <span class="w"> </span><span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Perl" data-mw-thread-id="h-Perl-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Perl-Code_samples_for_common_languages"></span>Perl<span data-mw-comment-end="h-Perl-Code_samples_for_common_languages"></span></h3></div> <div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span></span><span class="k">use</span><span class="w"> </span><span class="nn">User::pwent</span><span class="p">;</span> <span class="k">use</span><span class="w"> </span><span class="nn">DBI</span><span class="p">;</span> <span class="k">my</span><span class="w"> </span><span class="nv">$database</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"enwiki_p"</span><span class="p">;</span> <span class="k">my</span><span class="w"> </span><span class="nv">$host</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"tools.db.svc.wikimedia.cloud"</span><span class="p">;</span> <span class="k">my</span><span class="w"> </span><span class="nv">$dbh</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nn">DBI</span><span class="o">-></span><span class="nb">connect</span><span class="p">(</span> <span class="w"> </span><span class="s">"DBI:mysql:database=$database;host=$host;"</span> <span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">"mysql_read_default_file="</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="nb">getpwuid</span><span class="p">(</span><span class="vg">$<</span><span class="p">)</span><span class="o">-></span><span class="n">dir</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="s">"/replica.my.cnf"</span><span class="p">,</span> <span class="w"> </span><span class="nb">undef</span><span class="p">,</span><span class="w"> </span><span class="nb">undef</span><span class="p">)</span><span class="w"> </span><span class="ow">or</span><span class="w"> </span><span class="nb">die</span><span class="w"> </span><span class="s">"Error: $DBI::err, $DBI::errstr"</span><span class="p">;</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Python" data-mw-thread-id="h-Python-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Python-Code_samples_for_common_languages"></span><span id="Python_2"></span>Python<span data-mw-comment-end="h-Python-Code_samples_for_common_languages"></span></h3></div> <p>Without installing the toolforge library, this will work: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="kn">import</span> <span class="nn">configparser</span> <span class="kn">import</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="nn">pymysql</span> <span class="kn">import</span> <span class="nn">pymysql.cursors</span> <span class="n">replica</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="o">.</span><span class="n">home</span><span class="p">()</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s2">"replica.my.cnf"</span><span class="p">)</span> <span class="n">config</span> <span class="o">=</span> <span class="n">configparser</span><span class="o">.</span><span class="n">ConfigParser</span><span class="p">()</span> <span class="n">config</span><span class="o">.</span><span class="n">read_string</span><span class="p">(</span><span class="n">replica</span><span class="o">.</span><span class="n">read_text</span><span class="p">())</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">pymysql</span><span class="o">.</span><span class="n">connections</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span> <span class="n">host</span><span class="o">=</span><span class="s2">"commonswiki.analytics.db.svc.wikimedia.cloud"</span><span class="p">,</span> <span class="n">database</span><span class="o">=</span><span class="s2">"commonswiki_p"</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"client"</span><span class="p">,</span> <span class="s2">"user"</span><span class="p">),</span> <span class="n">password</span><span class="o">=</span><span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"client"</span><span class="p">,</span> <span class="s2">"password"</span><span class="p">),</span> <span class="n">cursorclass</span><span class="o">=</span><span class="n">pymysql</span><span class="o">.</span><span class="n">cursors</span><span class="o">.</span><span class="n">DictCursor</span><span class="p">,</span> <span class="p">)</span> <span class="k">with</span> <span class="n">connection</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span> <span class="k">as</span> <span class="n">cur</span><span class="p">:</span> <span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">query</span><span class="p">)</span> <span class="c1"># Or something....</span> <span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </pre></div> <p>Using <a href="/wiki/User:Legoktm/toolforge_library" class="mw-redirect" title="User:Legoktm/toolforge library">User:Legoktm/toolforge library</a>, however, is probably the easiest way. This wrapper library supports both Python 3 and legacy Python 2 applications and provides convenience functions for connecting to the Wiki Replica databases. </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="kn">import</span> <span class="nn">toolforge</span> <span class="n">conn</span> <span class="o">=</span> <span class="n">toolforge</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'enwiki'</span><span class="p">)</span> <span class="c1"># You can also use "enwiki_p"</span> <span class="c1"># conn is a pymysql.connection object.</span> <span class="k">with</span> <span class="n">conn</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span> <span class="k">as</span> <span class="n">cur</span><span class="p">:</span> <span class="n">cur</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">query</span><span class="p">)</span> <span class="c1"># Or something....</span> </pre></div> <p>We used to recommend <a rel="nofollow" class="external text" href="http://packages.python.org/oursql/">oursql</a> as well, but <a href="https://phabricator.wikimedia.org/T215963" class="extiw" title="phab:T215963">as of 2019-02-20</a> it seems to be abandoned or at least not actively maintained and failing to compile against MariaDB client libraries. </p> <div class="mw-heading mw-heading3"><h3 id="Python:_Django" data-mw-thread-id="h-Python:_Django-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Python:_Django-Code_samples_for_common_languages"></span>Python: Django<span data-mw-comment-end="h-Python:_Django-Code_samples_for_common_languages"></span></h3></div> <p>If you are using Django, first install mysqlclient (inside your tool's virtual environment, accessed via a <code>webservice shell</code>): </p> <pre>export MYSQLCLIENT_CFLAGS="-I/usr/include/mariadb/" export MYSQLCLIENT_LDFLAGS="-L/usr/lib/x86_64-linux-gnu/ -lmariadb" pip install mysqlclient </pre> <p>Then insert the database in the settings.py file as following, with s12345 your user name: </p> <div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span></span><span class="kn">import</span> <span class="nn">configparser</span> <span class="kn">import</span> <span class="nn">os</span> <span class="n">HOME</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'HOME'</span><span class="p">)</span> <span class="c1">#get environment variable $HOME</span> <span class="n">replica_path</span><span class="o">=</span><span class="n">HOME</span> <span class="o">+</span> <span class="s1">'/replica.my.cnf'</span> <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">replica_path</span><span class="p">):</span> <span class="c1">#check that the file is found</span> <span class="n">config</span> <span class="o">=</span> <span class="n">configparser</span><span class="o">.</span><span class="n">ConfigParser</span><span class="p">()</span> <span class="n">config</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">replica_path</span><span class="p">)</span> <span class="k">else</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s1">'replica.my.cnf file not found'</span><span class="p">)</span> <span class="n">DATABASES</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">'default'</span><span class="p">:</span> <span class="p">{</span> <span class="s1">'ENGINE'</span><span class="p">:</span> <span class="s1">'django.db.backends.mysql'</span><span class="p">,</span> <span class="s1">'NAME'</span><span class="p">:</span> <span class="s1">'s12345__mydbname'</span><span class="p">,</span> <span class="s1">'USER'</span><span class="p">:</span> <span class="n">config</span><span class="p">[</span><span class="s1">'client'</span><span class="p">][</span><span class="s1">'user'</span><span class="p">],</span> <span class="c1">#for instance "s12345"</span> <span class="s1">'PASSWORD'</span><span class="p">:</span> <span class="n">config</span><span class="p">[</span><span class="s1">'client'</span><span class="p">][</span><span class="s1">'password'</span><span class="p">],</span> <span class="s1">'HOST'</span><span class="p">:</span> <span class="s1">'tools.db.svc.wikimedia.cloud'</span><span class="p">,</span> <span class="s1">'PORT'</span><span class="p">:</span> <span class="s1">''</span><span class="p">,</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="PHP_(using_PDO)" data-mw-thread-id="h-PHP_(using_PDO)-Code_samples_for_common_languages"><span id="PHP_.28using_PDO.29"></span><span data-mw-comment-start="" id="h-PHP_(using_PDO)-Code_samples_for_common_languages"></span>PHP (using <a rel="nofollow" class="external text" href="http://php.net/manual/book.pdo.php">PDO</a>)<span data-mw-comment-end="h-PHP_(using_PDO)-Code_samples_for_common_languages"></span></h3></div> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="cp"><?php</span> <span class="nv">$ts_pw</span> <span class="o">=</span> <span class="nb">posix_getpwuid</span><span class="p">(</span><span class="nb">posix_getuid</span><span class="p">());</span> <span class="nv">$ts_mycnf</span> <span class="o">=</span> <span class="nb">parse_ini_file</span><span class="p">(</span><span class="nv">$ts_pw</span><span class="p">[</span><span class="s1">'dir'</span><span class="p">]</span> <span class="o">.</span> <span class="s2">"/replica.my.cnf"</span><span class="p">);</span> <span class="nv">$db</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PDO</span><span class="p">(</span><span class="s2">"mysql:host=enwiki.analytics.db.svc.wikimedia.cloud;dbname=enwiki_p"</span><span class="p">,</span> <span class="nv">$ts_mycnf</span><span class="p">[</span><span class="s1">'user'</span><span class="p">],</span> <span class="nv">$ts_mycnf</span><span class="p">[</span><span class="s1">'password'</span><span class="p">]);</span> <span class="nb">unset</span><span class="p">(</span><span class="nv">$ts_mycnf</span><span class="p">,</span> <span class="nv">$ts_pw</span><span class="p">);</span> <span class="nv">$q</span> <span class="o">=</span> <span class="nv">$db</span><span class="o">-></span><span class="na">prepare</span><span class="p">(</span><span class="s1">'select * from page where page_id = :id'</span><span class="p">);</span> <span class="nv">$q</span><span class="o">-></span><span class="na">execute</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">':id'</span> <span class="o">=></span> <span class="mi">843020</span><span class="p">));</span> <span class="nb">print_r</span><span class="p">(</span><span class="nv">$q</span><span class="o">-></span><span class="na">fetchAll</span><span class="p">());</span> <span class="cp">?></span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="PHP_(using_MySQLi)" data-mw-thread-id="h-PHP_(using_MySQLi)-Code_samples_for_common_languages"><span id="PHP_.28using_MySQLi.29"></span><span data-mw-comment-start="" id="h-PHP_(using_MySQLi)-Code_samples_for_common_languages"></span>PHP (using <a rel="nofollow" class="external text" href="http://php.net/manual/book.mysqli.php">MySQLi</a>)<span data-mw-comment-end="h-PHP_(using_MySQLi)-Code_samples_for_common_languages"></span></h3></div> <div class="mw-highlight mw-highlight-lang-php mw-content-ltr" dir="ltr"><pre><span></span><span class="cp"><?php</span> <span class="nv">$ts_pw</span> <span class="o">=</span> <span class="nb">posix_getpwuid</span><span class="p">(</span><span class="nb">posix_getuid</span><span class="p">());</span> <span class="nv">$ts_mycnf</span> <span class="o">=</span> <span class="nb">parse_ini_file</span><span class="p">(</span><span class="nv">$ts_pw</span><span class="p">[</span><span class="s1">'dir'</span><span class="p">]</span> <span class="o">.</span> <span class="s2">"/replica.my.cnf"</span><span class="p">);</span> <span class="nv">$mysqli</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">mysqli</span><span class="p">(</span><span class="s1">'enwiki.analytics.db.svc.wikimedia.cloud'</span><span class="p">,</span> <span class="nv">$ts_mycnf</span><span class="p">[</span><span class="s1">'user'</span><span class="p">],</span> <span class="nv">$ts_mycnf</span><span class="p">[</span><span class="s1">'password'</span><span class="p">],</span> <span class="s1">'enwiki_p'</span><span class="p">);</span> <span class="nb">unset</span><span class="p">(</span><span class="nv">$ts_mycnf</span><span class="p">,</span> <span class="nv">$ts_pw</span><span class="p">);</span> <span class="nv">$stmt</span> <span class="o">=</span> <span class="nv">$mysqli</span><span class="o">-></span><span class="na">prepare</span><span class="p">(</span><span class="s1">'select * from page where page_id = ?'</span><span class="p">);</span> <span class="nv">$id</span> <span class="o">=</span> <span class="mi">843020</span><span class="p">;</span> <span class="nv">$stmt</span><span class="o">-></span><span class="na">bind_param</span><span class="p">(</span><span class="s1">'i'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">);</span> <span class="nv">$stmt</span><span class="o">-></span><span class="na">execute</span><span class="p">();</span> <span class="nv">$result</span> <span class="o">=</span> <span class="nv">$stmt</span><span class="o">-></span><span class="na">get_result</span><span class="p">();</span> <span class="nb">print_r</span><span class="p">(</span><span class="nv">$result</span><span class="o">-></span><span class="na">fetch_all</span><span class="p">(</span><span class="nx">MYSQLI_BOTH</span><span class="p">));</span> <span class="cp">?></span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Java" data-mw-thread-id="h-Java-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Java-Code_samples_for_common_languages"></span>Java<span data-mw-comment-end="h-Java-Code_samples_for_common_languages"></span></h3></div> <div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span></span><span class="n">Class</span><span class="p">.</span><span class="na">forName</span><span class="p">(</span><span class="s">"com.mysql.jdbc.Driver"</span><span class="p">).</span><span class="na">newInstance</span><span class="p">();</span> <span class="n">Properties</span><span class="w"> </span><span class="n">mycnf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Properties</span><span class="p">();</span> <span class="n">mycnf</span><span class="p">.</span><span class="na">load</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">FileInputStream</span><span class="p">(</span><span class="n">System</span><span class="p">.</span><span class="na">getProperty</span><span class="p">(</span><span class="s">"user.home"</span><span class="p">)</span><span class="o">+</span><span class="s">"/replica.my.cnf"</span><span class="p">));</span> <span class="n">String</span><span class="w"> </span><span class="n">password</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mycnf</span><span class="p">.</span><span class="na">getProperty</span><span class="p">(</span><span class="s">"password"</span><span class="p">);</span> <span class="n">password</span><span class="o">=</span><span class="n">password</span><span class="p">.</span><span class="na">substring</span><span class="p">((</span><span class="n">password</span><span class="p">.</span><span class="na">startsWith</span><span class="p">(</span><span class="s">"\""</span><span class="p">))</span><span class="o">?</span><span class="mi">1</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">password</span><span class="p">.</span><span class="na">length</span><span class="p">()</span><span class="o">-</span><span class="p">((</span><span class="n">password</span><span class="p">.</span><span class="na">startsWith</span><span class="p">(</span><span class="s">"\""</span><span class="p">))</span><span class="o">?</span><span class="mi">1</span><span class="p">:</span><span class="mi">0</span><span class="p">));</span> <span class="n">mycnf</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">"password"</span><span class="p">,</span><span class="w"> </span><span class="n">password</span><span class="p">);</span> <span class="n">mycnf</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">"useOldUTF8Behavior"</span><span class="p">,</span><span class="w"> </span><span class="s">"true"</span><span class="p">);</span> <span class="n">mycnf</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">"useUnicode"</span><span class="p">,</span><span class="w"> </span><span class="s">"true"</span><span class="p">);</span> <span class="n">mycnf</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">"characterEncoding"</span><span class="p">,</span><span class="w"> </span><span class="s">"UTF-8"</span><span class="p">);</span> <span class="n">mycnf</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">"connectionCollation"</span><span class="p">,</span><span class="w"> </span><span class="s">"utf8_general_ci"</span><span class="p">);</span> <span class="n">String</span><span class="w"> </span><span class="n">url</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"jdbc:mysql://tools.db.svc.wikimedia.cloud:3306/enwiki_p"</span><span class="p">;</span> <span class="n">Connection</span><span class="w"> </span><span class="n">conn</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">DriverManager</span><span class="p">.</span><span class="na">getConnection</span><span class="p">(</span><span class="n">url</span><span class="p">,</span><span class="w"> </span><span class="n">mycnf</span><span class="p">);</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Node.js" data-mw-thread-id="h-Node.js-Code_samples_for_common_languages"><span data-mw-comment-start="" id="h-Node.js-Code_samples_for_common_languages"></span>Node.js<span data-mw-comment-end="h-Node.js-Code_samples_for_common_languages"></span></h3></div> <p><a rel="nofollow" class="external text" href="https://www.npmjs.com/package/mysql2">mysql2</a> client provides a promise-based interface. </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="kd">const</span><span class="w"> </span><span class="nx">mysql</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'mysql2/promise'</span><span class="p">);</span> <span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">sample</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">connection</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="nx">mysql</span><span class="p">.</span><span class="nx">createConnection</span><span class="p">({</span> <span class="w"> </span><span class="nx">host</span><span class="o">:</span><span class="w"> </span><span class="s1">'tools.db.svc.wikimedia.cloud'</span><span class="p">,</span><span class="w"> </span> <span class="w"> </span><span class="nx">port</span><span class="o">:</span><span class="w"> </span><span class="mf">3306</span><span class="p">,</span> <span class="w"> </span><span class="nx">database</span><span class="o">:</span><span class="w"> </span><span class="s1">'s12345__mydbname'</span><span class="p">,</span><span class="w"> </span> <span class="w"> </span><span class="nx">user</span><span class="o">:</span><span class="w"> </span><span class="s1">'s12345'</span><span class="p">,</span><span class="w"> </span> <span class="w"> </span><span class="nx">password</span><span class="o">:</span><span class="w"> </span><span class="s1">''</span> <span class="w"> </span><span class="p">});</span> <span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="p">[</span><span class="nx">rows</span><span class="p">,</span><span class="w"> </span><span class="nx">fields</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="nx">connection</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="s1">'SELECT * FROM table WHERE name = ? AND age > ?'</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="s1">'Morty'</span><span class="p">,</span><span class="w"> </span><span class="mf">14</span><span class="p">]);</span> <span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">let</span><span class="w"> </span><span class="nx">row</span><span class="w"> </span><span class="ow">in</span><span class="w"> </span><span class="nx">rows</span><span class="p">)</span><span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">row</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p><br/> </p> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="See_also" data-mw-thread-id="h-See_also"><span data-mw-comment-start="" id="h-See_also"></span>See also<span data-mw-comment-end="h-See_also"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-See_also","replies":[]}}--></div> <ul><li><a href="/wiki/Help:Trove_database_user_guide" title="Help:Trove database user guide">Help:Trove database user guide</a></li> <li><a href="/wiki/Portal:Data_Services/Admin/Wiki_Replicas" title="Portal:Data Services/Admin/Wiki Replicas">Portal:Data Services/Admin/Wiki Replicas</a></li> <li><a href="https://phabricator.wikimedia.org/phame/post/view/70/new_wiki_replica_servers_ready_for_use/" class="extiw" title="phab:phame/post/view/70/new wiki replica servers ready for use/">"New Wiki Replica servers ready for use"</a>(announcement post, September 25, 2017)</li></ul> <div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2 id="Note" data-mw-thread-id="h-Note"><span data-mw-comment-start="" id="h-Note"></span>Note<span data-mw-comment-end="h-Note"></span></h2><!--__DTELLIPSISBUTTON__{"threadItem":{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Note","replies":[]}}--></div> <ol class="references"> <li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1">↑</a></span> <span class="reference-text"><a class="external free" href="https://gerrit.wikimedia.org/r/plugins/gitiles/operations/puppet/+/refs/heads/production/hieradata/role/common/wmcs/db/wikireplicas/web_multiinstance.yaml#9">https://gerrit.wikimedia.org/r/plugins/gitiles/operations/puppet/+/refs/heads/production/hieradata/role/common/wmcs/db/wikireplicas/web_multiinstance.yaml#9</a></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2">↑</a></span> <span class="reference-text"><a class="external free" href="https://gerrit.wikimedia.org/r/plugins/gitiles/operations/puppet/+/refs/heads/production/hieradata/role/common/wmcs/db/wikireplicas/analytics_multiinstance.yaml#9">https://gerrit.wikimedia.org/r/plugins/gitiles/operations/puppet/+/refs/heads/production/hieradata/role/common/wmcs/db/wikireplicas/analytics_multiinstance.yaml#9</a></span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><a href="#cite_ref-3">↑</a></span> <span class="reference-text">If your private key is in a RFC4716 format, you will have to convert it to a PEM key.</span> </li> </ol> <!-- NewPP limit report Parsed by mw‐api‐ext.codfw.main‐58458956bc‐9vf9h Cached time: 20241214011631 Cache expiry: 2592000 Reduced expiry: false Complications: [show‐toc] DiscussionTools time usage: 0.068 seconds CPU time usage: 0.271 seconds Real time usage: 0.301 seconds Preprocessor visited node count: 2500/1000000 Post‐expand include size: 21518/2097152 bytes Template argument size: 11524/2097152 bytes Highest expansion depth: 13/100 Expensive parser function count: 36/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 64244/5000000 bytes Lua time usage: 0.004/10.000 seconds Lua memory usage: 555053/52428800 bytes --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 123.561 1 -total 39.26% 48.513 2 Template:Tracked 29.68% 36.673 6 Template:Dir 16.79% 20.747 6 Template:Pagelang 16.56% 20.462 1 Template:Toolforge_nav 14.53% 17.950 1 Template:Navigation_sidebar 13.56% 16.751 8 Template:Note 7.29% 9.005 2 Template:See_also 5.20% 6.420 2 Template:See 4.63% 5.718 3 Template:Warning --> <!-- Saved in parser cache with key labswiki:pcache:18678:|#|:idhash:canonical and timestamp 20241214011648 and revision id 2254601. Rendering was triggered because: edit-page --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?useformat=desktop&type=1x1&usesul3=0" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://wikitech.wikimedia.org/w/index.php?title=Help:Toolforge/Database&oldid=2254601">https://wikitech.wikimedia.org/w/index.php?title=Help:Toolforge/Database&oldid=2254601</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Special:Categories" title="Special:Categories">Categories</a>: <ul><li><a href="/wiki/Category:Toolforge" title="Category:Toolforge">Toolforge</a></li><li><a href="/wiki/Category:How-to-guide" title="Category:How-to-guide">How-to-guide</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 14 December 2024, at 01:16.</li> <li id="footer-info-copyright">Text is available under the <a rel="nofollow" class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-ShareAlike License</a>; additional terms may apply. See <a class="external text" href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use">Terms of Use</a> for details.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Main_Page">About Wikitech</a></li> <li id="footer-places-disclaimers"><a href="https://foundation.wikimedia.org/wiki/General_disclaimer">Disclaimers</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/wikitech.wikimedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//wikitech.wikimedia.org/w/index.php?title=Help:Toolforge/Database&mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.canary-65c988fd6-wxzln","wgBackendResponseTime":78,"wgDiscussionToolsPageThreads":[{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Connecting_to_the_database_replicas","replies":[{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Naming_conventions-Connecting_to_the_database_replicas","replies":[{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-analytics_vs_web-Naming_conventions","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Language_codes_and_project_families-Naming_conventions","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Shards-Naming_conventions","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Old_names-Naming_conventions","replies":[]}]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Connection_handling_policy-Connecting_to_the_database_replicas","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Connecting_to_the_wiki_replicas_from_other_Cloud_VPS_projects-Connecting_to_the_database_replicas","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Connecting_to_the_database_replicas_from_your_own_computer-Connecting_to_the_database_replicas","replies":[{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-SSH_tunneling_for_local_testing_which_makes_use_of_Wiki_Replica_databases-Connecting_to_the_database_replicas_from_your_own_computer","replies":[]}]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-TLS_connection_failures-Connecting_to_the_database_replicas","replies":[]}]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Databases","replies":[{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Replica_database_schema_(tables_and_indexes)-Databases","replies":[{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Stability_of_the_mediawiki_database_schema-Replica_database_schema_(tables_and_indexes)","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Tables_for_revision_or_logging_queries_involving_user_names_and_IDs-Replica_database_schema_(tables_and_indexes)","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Redacted_tables-Replica_database_schema_(tables_and_indexes)","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Unavailable_tables-Replica_database_schema_(tables_and_indexes)","replies":[]}]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Metadata_database-Databases","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Identifying_lag-Databases","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-User_databases-Databases","replies":[{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Privileges_on_the_database-User_databases","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-Steps_to_create_a_user_database-User_databases","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-ToolsDB_read-only_replica_host-User_databases","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-ToolsDB_Backups-User_databases","replies":[]},{"headingLevel":4,"name":"h-","type":"heading","level":0,"id":"h-ToolsDB_Caveats-User_databases","replies":[]}]}]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Query_Limits","replies":[]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Example_queries","replies":[]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Connecting_with...","replies":[{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-MySQL_Workbench-Connecting_with...","replies":[]}]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Code_samples_for_common_languages","replies":[{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Bash-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-C-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Perl-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Python-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Python:_Django-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-PHP_(using_PDO)-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-PHP_(using_MySQLi)-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Java-Code_samples_for_common_languages","replies":[]},{"headingLevel":3,"name":"h-","type":"heading","level":0,"id":"h-Node.js-Code_samples_for_common_languages","replies":[]}]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-See_also","replies":[]},{"headingLevel":2,"name":"h-","type":"heading","level":0,"id":"h-Note","replies":[]}],"wgPageParseReport":{"discussiontools":{"limitreport-timeusage":"0.068"},"limitreport":{"cputime":"0.271","walltime":"0.301","ppvisitednodes":{"value":2500,"limit":1000000},"postexpandincludesize":{"value":21518,"limit":2097152},"templateargumentsize":{"value":11524,"limit":2097152},"expansiondepth":{"value":13,"limit":100},"expensivefunctioncount":{"value":36,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":64244,"limit":5000000},"timingprofile":["100.00% 123.561 1 -total"," 39.26% 48.513 2 Template:Tracked"," 29.68% 36.673 6 Template:Dir"," 16.79% 20.747 6 Template:Pagelang"," 16.56% 20.462 1 Template:Toolforge_nav"," 14.53% 17.950 1 Template:Navigation_sidebar"," 13.56% 16.751 8 Template:Note"," 7.29% 9.005 2 Template:See_also"," 5.20% 6.420 2 Template:See"," 4.63% 5.718 3 Template:Warning"]},"scribunto":{"limitreport-timeusage":{"value":"0.004","limit":"10.000"},"limitreport-memusage":{"value":555053,"limit":52428800}},"cachereport":{"origin":"mw-api-ext.codfw.main-58458956bc-9vf9h","timestamp":"20241214011631","ttl":2592000,"transientcontent":false}}});});</script> </body> </html>