Databases (MySQL / phpMyAdmin)

What is SQL mode & Why is ONLY_FULL_GROUP_BY SQL mode

By the Domain India teamPublished 9 min read
Knowledge base article
Contents (8 sections)

SQL mode is a MySQL and MariaDB setting that decides how strict the database is about the queries and data you send it. One mode, ONLY_FULL_GROUP_BY, causes more "it worked on my old server" errors than any other. This guide explains what SQL mode is, what ONLY_FULL_GROUP_BY does, and what you can and can't change on shared hosting.

Key takeaways

sql_mode is a list of rules the database applies to every query. ONLY_FULL_GROUP_BY rejects a GROUP BY query that selects a column which is neither grouped nor inside an aggregate such as MAX(). On Domain India shared hosting you can't change the server-wide mode, but your application can run SET SESSION sql_mode = '…' on its own connection. The lasting fix is to write queries that work with ONLY_FULL_GROUP_BY switched on.

1. What SQL mode is

sql_mode is a comma-separated list of flags. Each flag switches one rule on: how to treat invalid dates, what happens when text is too long for a column, how quotes are read, and so on. It exists at two levels:

  • Global: the server default that every new connection starts with. Only the server administrator can change it, in the configuration file or with SET GLOBAL.
  • Session: the copy that belongs to one connection. Any database user can change it for their own connection with SET SESSION, and the change ends when the connection closes.

You can see both with one query, for example in phpMyAdmin's SQL tab:

sql
SELECT @@GLOBAL.sql_mode, @@SESSION.sql_mode;

2. Common modes and what they do

ModeWhat it does
STRICT_TRANS_TABLESRejects invalid or too-long values instead of silently cutting or changing them
ONLY_FULL_GROUP_BYRejects GROUP BY queries whose selected columns are not grouped or aggregated
ERROR_FOR_DIVISION_BY_ZEROTreats division by zero in an INSERT or UPDATE as an error instead of storing NULL
NO_ZERO_DATE, NO_ZERO_IN_DATEReject dates such as 0000-00-00 or 2026-00-15
NO_ENGINE_SUBSTITUTIONGives an error if the requested storage engine is not available, instead of using another
ANSI_QUOTESTreats double quotes as identifier quotes, like backticks, so "name" is a column, not a string

3. What ONLY_FULL_GROUP_BY does

When you group rows, each group becomes one result row. If you also select a column that has several different values inside the group, the database has to pick one. Without ONLY_FULL_GROUP_BY, it picks any value, and the choice is not guaranteed. With the mode on, the query is refused.

This query lists each customer's order count and also asks for order_date:

sql
SELECT customer_id, order_date, COUNT(*) AS orders
FROM orders
GROUP BY customer_id;

Each customer has many order dates, so order_date is ambiguous. With ONLY_FULL_GROUP_BY on, MySQL answers with error 1055, a message ending in "this is incompatible with sql_mode=only_full_group_by"; MariaDB says the column "isn't in GROUP BY".

4. How to fix a GROUP BY error

Decide which value you actually want, then say so in the query.

  1. Aggregate the column.
    If you want the latest date, ask for it: SELECT customer_id, MAX(order_date) AS last_order, COUNT(*) AS orders FROM orders GROUP BY customer_id;
  2. Group by it as well.
    If you want one row per customer per date, add it: GROUP BY customer_id, order_date.
  3. Join back for whole rows.
    To get the full latest order for each customer, find the latest date in a subquery and join it to the table, or use a window function such as ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC), supported by MySQL 8 and MariaDB 10.2 and later.
  4. Accept any value only on purpose.
    On MySQL 5.7 and later, ANY_VALUE(column) tells the server that any value from the group is fine. Use it only when all values in the group are the same.

MySQL 5.7.5 and later also accept a column that is fully determined by a grouped column, such as any column of a table grouped by its primary key. Don't rely on that if the code must also run on MariaDB; the fixes above work on both.

5. Why ONLY_FULL_GROUP_BY matters when you move servers

MySQL 5.7 and later switch ONLY_FULL_GROUP_BY on by default. MariaDB, including the default configuration on many hosts, does not. So code that runs happily on one server can fail after a move, or after a database upgrade, with no change to the code.

On Domain India's cPanel and DirectAdmin shared servers, which run MariaDB, the global mode is STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION (measured 23 September 2026). That means:

  • ONLY_FULL_GROUP_BY is off. Loose GROUP BY queries run, but they may fail when you move to a MySQL 8 server.
  • Strict mode is on. An INSERT with text longer than the column, or an invalid value, gives an error instead of being quietly cut. Fix the data or the column size rather than switching strict mode off.
You can't change the server-wide mode on shared hosting

SET GLOBAL sql_mode and editing my.cnf need administrator rights, which no shared hosting account has, and the global setting affects every customer on the server. Change the mode for your own connection instead (section 6), or fix the query. On a VPS you control the server and can set any global mode.

6. Set SQL mode for your own connection

Every database user can change the mode for their own session. Run the statement straight after connecting, and it applies to every query on that connection.

The simplest way is to give the full list you want. To turn ONLY_FULL_GROUP_BY on, for example to test code before moving to MySQL 8:

sql
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

To run an old application that you can't fix yet on a server where the mode is on, give the same list without it:

sql
SET SESSION sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Both lists work on MySQL 8 and on MariaDB. Leave out NO_AUTO_CREATE_USER: MariaDB still accepts it, but MySQL 8 removed it and rejects the statement.

In PHP with PDO, run it once after connecting:

php
$pdo = new PDO($dsn, $user, $pass);
$pdo->exec("SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'");

Frameworks have their own setting. In Laravel, the strict option in config/database.php controls the modes it sets, and a modes array lets you list them exactly. WordPress removes several strict modes, including ONLY_FULL_GROUP_BY, from its own connection automatically, so WordPress core is not affected; custom plugin queries should still be written correctly.

In phpMyAdmin, a SET SESSION statement applies only to the statements you run together with it in the same SQL box, because phpMyAdmin opens a new connection for each request.

7. Should you use ONLY_FULL_GROUP_BY?

Good for
  • Catches queries that return unpredictable results
  • Keeps your code ready for MySQL 8 servers, where the mode is on by default
  • Makes reports and totals trustworthy
Watch out for
  • Old scripts and plugins may break until their queries are fixed
  • Switching it off per session hides the problem rather than solving it

Our advice: write new code so that it passes with ONLY_FULL_GROUP_BY on, even though our shared servers don't require it. Test old applications with the mode switched on in a session before you move them to a new server.

8. Where Domain India fits

Shared hosting on cPanel and DirectAdmin gives you MariaDB databases with phpMyAdmin, which is enough for almost every website. For database details and connection settings, see how to connect to the MySQL database, and for errors, database troubleshooting.

If your application needs its own global SQL mode, a particular database version or server configuration, a VPS gives you root access to set them.

VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details

The card shows the live list price, excluding 18% GST.

What is sql_mode in MySQL?

sql_mode is a list of flags that control how strictly MySQL or MariaDB checks queries and data, such as whether invalid dates or too-long text are rejected. It has a global value set by the server administrator and a session value that each connection can change for itself.

What does ONLY_FULL_GROUP_BY mean?

With ONLY_FULL_GROUP_BY on, every column in the SELECT list of a GROUP BY query must either be in the GROUP BY clause or be inside an aggregate function such as MAX() or COUNT(). Otherwise the query is rejected, because the database would have to pick an arbitrary value.

How do I fix "this is incompatible with sql_mode=only_full_group_by"?

Change the query: wrap the extra column in an aggregate such as MAX(), add it to GROUP BY, or join back to get the full row you want. As a temporary measure, your application can remove the mode for its own connection with SET SESSION sql_mode.

Is ONLY_FULL_GROUP_BY enabled on Domain India shared hosting?

No. On 23 September 2026 the global sql_mode on our cPanel and DirectAdmin shared servers was STRICT_TRANS_TABLES, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER and NO_ENGINE_SUBSTITUTION. Your application can switch ONLY_FULL_GROUP_BY on for its own connection if you want to test with it.

Can I change the global sql_mode on shared hosting?

No. Changing the global mode needs server administrator rights and would affect every account on the server. Use SET SESSION sql_mode in your application after connecting, or fix the query. On a VPS you can set the global mode yourself.

Can I turn off strict mode on shared hosting?

Not for the server, but your application can change sql_mode for its own connection. It is better to fix the cause, such as text longer than the column allows, because strict mode stops data from being silently cut or changed.

Ready to fix your queries? Check the modes with SELECT @@SESSION.sql_mode; in phpMyAdmin, apply the fixes in section 4, and open a support ticket with the exact error message if a query still fails, or compare VPS plans if you need your own server settings.

Stuck on a database error?

Send us the exact error message, the query or page that causes it and the database name, and we will help you find the cause.

Open a support ticket

Ready when you are

Get DirectAdmin hosting from ₹100/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
SQL Mode and ONLY_FULL_GROUP_BY Explained | Domain India