24

I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.

After following the instructions in the website and making the following my.cnf file:

[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF

log_error = /var/log/mysql/error.log

# Remove case sensitive in table names
lower_case_table_names=1

I get the following error:

2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').

What should I change so that data dictionary is aligned to server settings?

2

7 Answers 7

53

So far, I can get it to work with a workaround (I originally posted on askubuntu): by re-initializing MySQL with the new value for lower_case_table_names after its installation. The following steps apply to a new installation. If you have already data in a database, export it first to import it back later:

  1. Install MySQL:
    sudo apt-get update    
    sudo apt-get install mysql-server -y
    
  2. Stop the MySQL service:
    sudo service mysql stop
    
  3. Delete the MySQL data directory:
    sudo rm -rf /var/lib/mysql
    
  4. Recreate the MySQL data directory (yes, it is not sufficient to just delete its content):
    sudo mkdir /var/lib/mysql    
    sudo chown mysql:mysql /var/lib/mysql
    sudo chmod 700 /var/lib/mysql
    
  5. Add lower_case_table_names = 1 to the [mysqld] section in /etc/mysql/mysql.conf.d/mysqld.cnf.
  6. Re-initialize MySQL with --lower_case_table_names=1:
    sudo mysqld --defaults-file=/etc/mysql/my.cnf --initialize --lower_case_table_names=1 --user=mysql --console
    
  7. Start the MySQL service:
    sudo service mysql start
    
  8. Retrieve the new generated password for MySQL user root:
    sudo grep 'temporary password' /var/log/mysql/error.log
    
  9. Change the password of MySQL user root either by:
    sudo mysql -u root -p
    
    and executing:
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPa$$w0rd';
    
    afterwards, OR by calling the "hardening" script anyway:
    sudo mysql_secure_installation
    

After that, you can verify the lower_case_table_names setting by entering the MySQL shell:

sudo mysql -u root -p

and executing:

SHOW VARIABLES LIKE 'lower_case_%';

Expected output:

+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 1     |
+------------------------+-------+
4
  • 1
    You save my life.
    – Naveen Roy
    Jun 22, 2022 at 18:10
  • At this point I don't know how many times I came back to this brilliant answer to solve problems, you're the best
    – Felype
    Jun 23, 2022 at 22:16
  • 1
    Yes this a great answer... but why is mysql like this? Apr 2 at 0:36
  • I tried a lot but your answer worked for me mysql 8 and ubunutu 22. thank you very much. Jun 7 at 7:41
8

As per this link, lower_case_table_names should be set together with --initialize option.

6
  • Thank you very much. I should've imagined that, but I couldn't find any reference at any place.
    – asuka
    Aug 11, 2018 at 22:02
  • 6
    Can you give me an example on how to use this option? Oct 31, 2018 at 14:27
  • @ChristophAdamakis , the example that you require was already posted by Christian Fernando.
    – Praveen E
    Nov 1, 2018 at 5:29
  • 12
    @PraveenE Where do you set the --initialize option? Jul 23, 2020 at 12:05
  • 1
    does not work with deb / ubuntu releases as they initiate the db already!
    – UnnameDSoS
    Jan 19, 2022 at 14:55
4

MySQL Documentation says

lower_case_table_names can only be configured while initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.

https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html

0
1

The best way to prevent this problem is :At first add

[mysqld]
lower_case_table_names=1

then start mysql service for first time.

But anyway if you have started the server already,to solve your problem:

1.stop mysql:

systemctl stop  mysql

2.clean data directory or change the default, the following is for new installations , if you have data in your database BACK UP them beforehand

rm -rf /var/lib/mysql

3.Insert lower_case_table_names = 1 in your my.cnf:

[mysqld]
lower_case_table_names=1

4.Start again

systemctl start mysqld
2
  • Thanks a lot its work, but I add only, [mysqld] lower_case_table_names=1, Because systemctl command not working.
    – Eranda J.
    May 8, 2020 at 15:38
  • 1
    Incomplete instructions. If you remove /var/lib/mysql and the binaries are gone. Your step 4 wouldn't work.
    – Allen King
    Aug 17, 2020 at 2:46
0

To fix this issue,

  1. Just take the backup of the existing db Schema using the following command inside bin folder (/usr/local/mysql/bin) ./mysqldump -uroot -p password > dump.sql

  2. Once the backup is taken delete the existing data folder in Mysql Home(/usr/local/mysql/) using the command rm -rf data

  3. Now add the configuration as "lower_case_table_names=1" in my.cnf under MYSQLD section (/etc/my.cnf)

  4. Now Initialize the data directory using the following command inside bin directory (/usr/local/mysql/bin)

For Secure mode ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console

For Insecure mode ./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --console

  1. Once the data directory initialized, For Insecure mode repeat the Installation again and For Secure mode use the root password which is initialized during the run time of data directory Initialization.

  2. Now import the existing dump file inside the Mysql Server using the command inside (/usr/local/mysql/bin) directory

./mysql -uroot -p password < file.sql

0

If anyone runs into this issue now, if you already initialized mysql, meaning you already had it up and running and then this error occurred, just comment out this line in the my.ini file.

lower_case_table_names=
0
0

Edit the /etc/mysql/my.cnf file. Add this:

[mysqld]
lower_case_table_names=1

After that you have to reinstall mysql. Ubuntu would keep your current configuration files:

sudo apt purge mysql-server
sudo apt autoremove

sudo apt install mysql-server

Not the answer you're looking for? Browse other questions tagged or ask your own question.