A site has zero or more MariaDB databases and zero or more database users. Each user signs in with its own password and reaches only the databases you give it, with all privileges or read only. You manage both from the site's Database tab.
What a new site starts with
| Type | Databases at creation |
|---|---|
| WordPress, WooCommerce, Laravel | one database and one user, the primary ones: the site's configuration uses them |
| PHP, Static | none, unless you turn on Create a database too when you create the site |
| Reverse proxy | none |
The primary database and the primary user carry the Primary badge. They cannot be deleted while the site exists, and the primary user always keeps all privileges on the primary database. You add more databases and users whenever the site needs them.
Look at the databases
Open the site and choose the Database tab. It has two sections:
- Databases: each database with Access (which users reach it, and how), Tables and Size. A dash means the sizes could not be read.
- Database users: each user with its Access on each database.
Read-only accounts see both sections and can open Quarry, but change nothing.
Add a database
- In Databases, press Add database.
- In Name, type the name, for example
shop_data. The name rules apply. - Press Create database.
The database is created by a task (Creating the database …). It is empty, and no user can reach it until you give one access: see change a user's privileges.
Add a database user
- In Database users, press Add user.
- In User, type the name, for example
reporting. The same rules as for databases apply. - Leave Password empty to have a strong one generated, or type your own: see the password rules.
- Under Privileges, choose for each database None, Read only or All privileges.
- Press Create user.
When the panel generated the password, the Save the password dialog shows the user and the password once. Copy them, then press I have saved it: the panel cannot show the password again.
The user signs in from this server only (<user>@localhost), with at most 50 connections at a time.
Change a user's privileges
- In Database users, press Privileges on the user's row.
- For each database choose None, Read only or All privileges.
- Press Save.
Read only grants SELECT, SHOW VIEW; All privileges grants ALL PRIVILEGES on that
database. The primary user cannot lose all privileges on the primary database.
Reset a user's password
- On the user's row, open the ⋯ menu and choose Reset password.
- Choose Generate a strong password, or Choose a password and type it.
- Press Reset password. A generated password is shown once, as for a new user.
What happens to the site's configuration depends on the user:
- the primary user of a WordPress or WooCommerce site: the panel writes the new password into
wp-config.phpat the same time. If that fails, the old password comes back and the error says so; - the primary user of any other site: the panel never writes a
.envfile. Put the new password in the site's configuration yourself, or the site stops reaching its database; - any other user: only the user changes. Applications that sign in as that user need the new password.
A password reset also ends the Quarry sessions signed in as that user.
Delete a database or a user
- On the row, open the ⋯ menu and choose Delete.
- Type the name to confirm, and confirm.
- Deleting a database deletes every table in it, and takes away every user's access to it. Its backups stay in the repository: the retention policy removes them later.
- Deleting a user stops every application that signs in as that user.
The menu item is disabled for the primary database and the primary user.
Open a database in Quarry
On a database's row, press Open in Quarry. Quarry opens in a new tab, already signed in for this site: see Use Quarry.
WordPress tools
On a WordPress or WooCommerce site, WordPress tools in the Databases section opens three tools that work on the primary database through wp-cli:
- Autoloaded options: how much data WordPress loads on every request, and the 20 largest options. Over 800 KB slows every uncached request.
- Search and replace: replaces a text in all the site's tables, keeping serialized data valid; GUIDs are left alone. Press Count replacements first, then Replace.
- Expired transients: press Find expired transients, then confirm to delete them.
After a replacement or a clean-up the site's cache is refreshed.
With cgctl
cgctl database list <site-id>
cgctl --wait database create <site-id> shop_data
cgctl database user-create <site-id> reporting shop_data:read site_7:all
<site-id>is the site's number.database user-createtakes the user's name, then one<database>:allor<database>:readfor each database it may reach. It always generates the password, which appears once in the answer.
Deleting, privileges and password resets are routes of the API:
DELETE /api/sites/<id>/databases/<name>?confirm=<name>,
PUT /api/sites/<id>/database-users/<name>/grants,
POST /api/sites/<id>/database-users/<name>/password and
DELETE /api/sites/<id>/database-users/<name>?confirm=<name>.
Next step
Use Quarry to browse and edit the tables.