MySQL for hosts
This page is for system administrators at a hosting company who provide MySQL databases for Exponential sites. It answers: where MySQL stands, how to create a site's database and user, what the driver needs from the server, how to use replicas, and how to back it up. MySQL is sixth in the official order: supported and tested in the project's CI, last only because the project recommends the others first for new sites. Sources: Database support and chapter 9.3.
Contents
- Where MySQL stands
- Versions and extension
- Creating a database per site
- Settings and install
- Replicas and persistent connections
- Backups
- Problems and their causes
- Checklist
- Related pages
Where MySQL stands
- The driver
eZMySQLiDBonmysqliis the one most third-party extensions were originally written against, so MySQL is the safe choice for a customer with older extensions that contain SQL of their own. - It shares the driver with MariaDB (MariaDB for hosts); for a host, the two are provisioned the same way.
- The project's CI runs its database tests against MySQL 8.0 on every push (test coverage).
Versions and extension
| Item | Value |
|---|---|
| Wizard floor | 4.1.1 (not a recommendation) |
| Practical minimum | a release your vendor still supports, with utf8mb4 and InnoDB |
| Seen working | 8.0 in CI |
| PHP extension | mysqli (php-mysqlnd on the RHEL family, php<version>-mysql on Debian and Ubuntu) |
| Installer names | wizard "MySQL Improved"; exp:install --db=mysql (also mysqli); kickstarter Type=mysqli |
Creating a database per site
CREATE DATABASE <customer> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER '<customer>'@'localhost' IDENTIFIED BY '<a strong password>';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,
LOCK TABLES, CREATE TEMPORARY TABLES
ON <customer>.* TO '<customer>'@'localhost';No global privilege is needed. The installer creates InnoDB tables when the server offers InnoDB, and transactions
need it. The MySQL update files of an upgrade start with SET default_storage_engine=InnoDB;
(chapter 9.3).
Settings and install
[DatabaseSettings]
DatabaseImplementation=ezmysqli
Server=localhost
# empty: 3306
Port=
User=<customer>
Password=<the password>
Database=<customer>
# a Unix socket instead of host and port, e.g. /var/lib/mysql/mysql.sock
Socket=disabled
Charset=utf-8
UsePersistentConnection=disabled
ConnectRetries=0EXP_INSTALL_DB_PASSWORD='<the password>' php bin/php/console exp:install --apply --db=mysql \
--db-host=127.0.0.1 --db-name=<customer> --db-user=<customer> --allow-root-userNote
The connection character set utf-8 is sent as MySQL's utf8, three bytes per character, so characters outside the
Basic Multilingual Plane, such as emoji, cannot pass through the connection even when the tables are utf8mb4.
Customers who need them should know this before they choose MySQL or MariaDB
(character sets).
Replicas and persistent connections
- Read replicas.
UseSlaveServer=enabledwithSlaveServerArray[],SlaveServerPort[],SlaverServerUser[],SlaverServerPassword[]andSlaverServerDatabase[](the keys really are spelledSlaver...) sends reads to a replica chosen at random per request; writes go toServer. Replication lag means a page may show content a few seconds old. - Persistent connections.
UsePersistentConnection=enabledkeeps one connection per PHP process (the driver prefixes the host withp:). Under Velocity's persistent workers each worker keeps its connection anyway. Size the server's connection limit for the number of PHP processes of every site that uses it.
Backups
mysqldump --single-transaction -u <customer> -p <customer> > <customer>.sql
mysql -u <customer> -p <customer> < <customer>.sql--single-transaction gives a consistent dump of InnoDB tables without locking them. A complete backup also contains
var/storage, settings/override and settings/siteaccess
(Backup and restore).
Problems and their causes
| Symptom | Cause |
|---|---|
| The "database cannot be reached" page | wrong host, user, password or database; since PHP 8.1 mysqli throws and the driver turns it into eZDBNoConnectionException |
Text with ? where accented letters were | the connection fell back to the server's default character set; set AlwaysLog[]=warning and look for "could not set the connection charset" in var/log/warning.log |
| The wizard refuses the database's character set | the database is not UTF-8; recreate it in utf8mb4 |
| Slow queries | [DatabaseSettings] QueryAnalysisOutput=enabled with SQLOutput=enabled shows MySQL's analysis in the debug output |
Checklist
- To do: A supported MySQL release with InnoDB.
- To do: One database per site in
utf8mb4, one user with the grants above. - To do:
mysqliin the web and the command line PHP. - To do: The server's connection limit sized for the PHP processes of every site on the server.
- To do:
mysqldump --single-transactionbackups scheduled and a restore tested.
Related pages
- Databases in the official order and MariaDB for hosts
- Database support: MySQL
- Chapter 9.3: MySQL and MariaDB
- Database backups per engine
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.