General MySQL guidelines
See System Requirements for supported versions of MySQL.
ÃÛ¶¹ÊÓƵ strongly recommends you observe the following standard when you set up your database:
- ÃÛ¶¹ÊÓƵ Commerce uses to improve database access during reindexing. These get created when the indexer mode is set to schedule. The application does not support any custom triggers in the database because custom triggers can introduce incompatibilities with future ÃÛ¶¹ÊÓƵ Commerce versions.
- Familiarize yourself with before you continue.
- To enhance your database security posture, enable the SQL mode to prevent storing invalid data values, which might cause unwanted database interactions.
- ÃÛ¶¹ÊÓƵ Commerce does not support MySQL statement-based replication. Make sure you use only .
CREATE TEMPORARY TABLE
statements inside transactions, which are with database implementations use GTID-based replication, such as . Consider MySQL for Cloud SQL 8.0 as an alternative.Installing MySQL on Ubuntu
ÃÛ¶¹ÊÓƵ Commerce 2.4 requires a clean installation of MySQL 8.0. Follow the links below for instructions on installing MySQL on your machine.
If you expect to import large numbers of products, you can increase the value for that is larger than the default, 16 MB.
max_allowed_packet
value. ÃÛ¶¹ÊÓƵ Commerce on cloud infrastructure Starter customers can increase the value by updating the configuration in the /etc/mysql/mysql.cnf
file.To increase the value, open the /etc/mysql/mysql.cnf
file in a text editor and locate the value for max_allowed_packet
. Save your changes to the mysql.cnf
file, close the text editor, and restart MySQL (service mysql restart
).
To optionally verify the value that you set, enter the following command at a mysql>
prompt:
SHOW VARIABLES LIKE 'max_allowed_packet';
Then, Configure the database instance.
MySQL 8 changes
For ÃÛ¶¹ÊÓƵ Commerce 2.4, we added support for MySQL 8.
This section describes major changes to MySQL 8 that developers should be aware of.
Removed width for integer types (padding)
The display width specification for integer data types (TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT) has been deprecated in MySQL 8.0.17. Statements that include data-type definitions in their output no longer show the display width for integer types, except for TINYINT(1). MySQL Connectors assume that TINYINT(1) columns originated as BOOLEAN columns. This exception enables them to continue to make that assumption.
Example
Describe admin_user at mysql 8.19
int unsigned
NULL
auto_increment
firstname
varchar(32)
NULL
lastname
varchar(32
)NULL
email
varchar(128)
NULL
username
varchar(40)
NULL
password
varchar(255)
NULL
created
timestamp
CURRENT_TIMESTAMP
DEFAULT_GENERATED
modified
timestamp
CURRENT_TIMESTAMP
DEFAULT_GENERATED
on update CURRENT_TIMESTAMP
logdate
timestamp
NULL
lognum
smallint unsigned
0
Except for TINYINT(1), all integer padding (TINYINT > 1, SMALLINT, MEDIUMINT, INT, BIGINT) should be removed from the db_schema.xml
file.
For more information, see .
Default ORDER BY behavior
Before 8.0, entries were sorted by the foreign key. Default sort order depends on the engine that is used.
Always specify a sort order if your code depends on a specific sort.
Deprecated ASC and DESC qualifiers for GROUP BY
As of MySQL 8.0.13, the deprecated ASC
or DESC
qualifiers for GROUP BY
clauses have been removed. Queries that previously relied on GROUP BY
sorting may produce results that differ from previous MySQL versions. To produce a given sort order, provide an ORDER BY
clause.
Commerce and MySQL 8
There have been some changes to ÃÛ¶¹ÊÓƵ Commerce to properly support MySQL 8.
Query and Insert Behavior
ÃÛ¶¹ÊÓƵ Commerce disabled the regular validation behavior by setting SET SQL_MODE=‘’ in /lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php:424.
. With validation disabled, it is possible that MySQL truncates data. In MySQL, the Query behavior has changed: Select * on my_table where IP='127.0.0.1'
no longer returns results because the IP address is now properly seen as a string, rather than an integer.
Upgrading from MySQL 5.7 to MySQL 8
To properly update MySQL from version 5.7 to version 8, you must follow these steps in order:
-
Upgrade ÃÛ¶¹ÊÓƵ Commerce to 2.4.0.
Test everything and make sure that your system works as expected. -
Enable maintenance mode:
code language-bash bin/magento maintenance:enable
-
Make a database backup:
code language-bash bin/magento setup:backup --db
-
Update MySQL to version 8.
-
Import the backed-up data into MySQL.
-
Clean the cache:
code language-bash bin/magento cache:clean
-
Disable maintenance mode:
code language-bash bin/magento maintenance:disable
Configuring the database instance
This section discusses how to create a database instance for ÃÛ¶¹ÊÓƵ Commerce. Although a new database instance is recommended, you can optionally install ÃÛ¶¹ÊÓƵ Commerce with an existing database instance.
To configure a MySQL database instance:
-
Log in to your database server as any user.
-
Get to a MySQL command prompt:
code language-bash mysql -u root -p
-
Enter the MySQL
root
user’s password when prompted. -
Enter the following commands in the order shown to create a database instance named
magento
with usernamemagento
:code language-sql create database magento;
code language-sql create user 'magento'@'localhost' IDENTIFIED BY 'magento';
code language-sql GRANT ALL ON magento.* TO 'magento'@'localhost';
code language-sql flush privileges;
-
Enter
exit
to quit the command prompt. -
Verify the database:
code language-bash mysql -u magento -p
If the MySQL monitor displays, you created the database properly. If an error displays, repeat the preceding commands.
-
If your web server and database server are on different hosts, perform the tasks discussed in this topic on the database server host then see Set up a remote MySQL database connection.
We recommend you configure your database instance as appropriate for your business. When configuring your database, please keep the following in mind:
-
Indexers require higher
tmp_table_size
andmax_heap_table_size
values (for example, 64 M). If you configure thebatch_size
parameter, you can adjust that value along with the table size settings to improve indexer performance. Refer to the Optimization Guide for more information. -
For optimal performance, make sure all MySQL and ÃÛ¶¹ÊÓƵ Commerce index tables can be kept in memory (for example, configure
innodb_buffer_pool_size
). -
Reindexing on MariaDB 10.4 takes more time compared to other MariaDB or MySQL versions. See Configuration best practices.
-
-
For MySQL
TIMESTAMP
fields to follow the preferences and composition expected by the application’s declarative schema architecture, the system variableexplicit_defaults_for_timestamp
must be set toon
.References:
If this setting is not enabled,
bin/magento setup:db:status
always reports that theDeclarative Schema is not up to date
.
explicit_defaults_for_timestamp
setting is deprecated. This setting controls deprecated TIMESTAMP behaviors that will be removed in a future MySQL release. When those behaviors are removed, the explicit_defaults_for_timestamp
setting is removed as well.explicit_defaults_for_timestamp
setting for MySQL (MariaDB) defaults to OFF.Reindexing on MariaDB 10.4 and 10.6 takes more time compared to previous MariaDB or MySQL versions. To speed up reindexing, we recommend setting these MariaDB configuration parameters:
If you experience performance degradation not related to indexation after upgrading to MariaDB 10.6, consider enabling the setting. For example, --query-cache-type=ON
.
Before upgrading ÃÛ¶¹ÊÓƵ Commerce on cloud infrastructure projects, you may also need to upgrade MariaDB (see MariaDB upgrade best practices).
For example:
- ÃÛ¶¹ÊÓƵ Commerce 2.4.6 with MariaDB version 10.5.1 or higher
- ÃÛ¶¹ÊÓƵ Commerce 2.3.5 with MariaDB version 10.3 or earlier
In addition to these recommendations, you should consult with your database administrator on configuring the following parameters: