When running MySQL 8 on Linux servers, you may encounter problems with case sensitivity in table names.
On Linux, file systems are case-sensitive, which means Table1
and table1
are treated as different objects. On Windows or macOS, however, MySQL defaults to case-insensitive behavior.
This difference can lead to issues such as:
- Failing imports of database dumps created on Windows servers
- Failing to synchronize data with Forex CRM systems that use lowercase table names as the MetaTrader 4 application uses uppercase format.
- WordPress or other CMS breaking due to mismatched table casing
- Replication errors when syncing from case-insensitive servers
The MySQL system variable lower_case_table_names
controls this behavior.
In this guide, we explain how to correctly configure lower_case_table_names=1
in MySQL 8 running on any Linux distribution (Debian, Ubuntu, CentOS, Rocky, AlmaLinux, etc.).
Prerequisites
- A server running Linux with MySQL 8.x installed
- Root or sudo access
- A full database backup (the process we describe in this tutorial wipes the MySQL system tables)
Step 1: Stop the MySQL Service
The command to stop MySQL differs slightly by distribution:
Debian/Ubuntu:
root@localhost:~$ systemctl stop mysql
CentOS/RHEL/RockyLinux/AlmaLinux:
root@localhost:~$ systemctl stop mysqld
Step 2: Check Existing Configurations
Make sure there are no conflicting entries for lower_case_table_names
in the mysql configuration files:
root@localhost:~$ grep -RIn "lower_case_table_names" /etc/mysql /etc/my.cnf* || true
Edit your MySQL configuration file (my.cnf) and set:
[mysqld]
lower_case_table_names=1
- Debian/Ubuntu:
/etc/mysql/mysql.conf.d/mysqld.cnf
- CentOS/RHEL-based:
/etc/my.cnf
or/etc/my.cnf.d/custom.cnf
Step 3: Confirm the Data Directory
Check which datadir MySQL is using:
root@localhost:~$ grep -RIn "^datadir" /etc/mysql /etc/my.cnf* || true
The default is usually /var/lib/mysql
.
Step 4: Wipe and Recreate the Data Directory
Important: This destroys MySQL system tables. Ensure you have backups !!!
root@localhost:~$ rm -rf /var/lib/mysql/*
root@localhost:~$ mkdir -p /var/lib/mysql
root@localhost:~$ chown mysql:mysql /var/lib/mysql
Note: Replace /var/lib/mysql
if your server uses a different datadir.
Step 5: Initialize MySQL with Lowercase Setting
Run the following command to reinitialize the system tables:
root@localhost:~$ sudo -u mysql /usr/sbin/mysqld \
--no-defaults \
--initialize-insecure \
--lower_case_table_names=1 \
--datadir=/var/lib/mysql \
--log-error=/var/log/mysql/error.log
This ensures the lower_case_table_names=1 is embedded in the system dictionary.
Step 6: Restart MySQL
Start the service again:
Debian/Ubuntu/CentOS/RHEL/RockyLinux/AlmaLinux:
root@localhost:~$ systemctl start mysql
Step 7: Verify the Configuration
Check if MySQL is now case-insensitive:
root@localhost:~$ mysql -u root --skip-password -e "SHOW VARIABLES LIKE 'lower_case_table_names';"
Expected output:
+------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | lower_case_table_names | 1 | +------------------------+-------+
Step 8: Reset the Root Password
Since MySQL was initialized insecurely, you must set a new root password:
root@localhost:~$ mysql -u root --skip-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword'; ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;"
Conclusion
By forcing lower_case_table_names=1
during initialization, you ensure consistent, case-insensitive table handling for your MySQL databases.
Remember: you must set this variable before the data dictionary is created — changing it afterward is not supported.
At NetShop ISP, we help businesses configure, optimize, and troubleshoot databases, servers, and hosting infrastructure. Need expert assistance with MySQL migrations or performance tuning? Get in touch with our team.