Procedure to change lower_case_table_names = 1 in MySQL 8.0 of CentOS 8.3

../

I have MySQL 8.0 installed on CentOS 8.3. I want to stop distinguishing between the case of table names and column names as in the Windows version. To do this, set my.cnf to lower_case_table_names = 1 and restart mysqld. That was fine before. However, for some time unknown, the procedure in MySQL 8.0 has not been easy. Lower_case_table_names can only be specified immediately after the initial installation of MySQL 8.0. To return to the initial installation state, you need to delete the datastore and recreate the datastore. Make a note of the procedure.

-(1) Take a dump of the existing DB -(2) Delete the data store in secret -(3) Set lower_case_table_names = 1 and recreate the datastore -(4) Set the root password -(5) Set GRANT by create database and create user -(6) Restore from dump

(1) Take a dump of the existing DB

Make a backup of the existing user-defined DB. Save all DB except mysql database. In the example below, it is a kankeri database and a xxx database.

$ mkdir -p /var/tmp/mysql
$ mysqldump -uroot -p kankeri > /var/tmp/dump-kankeri.sql
$ mysqldump -uroot -p xxx     > /var/tmp/dump-xxx.sql

(2) Delete the data store in secret

Gently delete the MySQL datastore (/ var/lib/mysql). It is safe to mv and save. You should also clear mysqld.log. Easy to check for errors later.

$ mv /var/lib/mysql /var/tmp/mysql
$ rm -f /var/log/mysql/mysqld.log
$ touch /var/log/mysql/mysqld.log
$ chown mysql.mysql /var/log/mysql/mysqld.log

(3) Set lower_case_table_names = 1 and recreate the datastore

First, write lower_case_table_names = 1 in mysql-server.cnf. Add to cnf in the initial state. If extra settings remain, it will be difficult to isolate when an error occurs.

$ vi /etc/my.cnf.d/mysql-server.cnf
[mysqld]
lower_case_table_names=1

Then recreate the datastore and start the service. At this point, make sure that you can start without error.

$ mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console
$ ls -l /var/lib/mysql
$ more /var/log/mysql/mysqld.log
$ systemctl start mysqld

(4) Set the root password

Add skip-grant-tables to mysql-server.cnf to set the root password and restart the service. If necessary, set the encoding as well. Enter the MySQL console with a root account without password authentication.

$ vi /etc/my.cnf.d/mysql-server.cnf
[mysqld]
character-set-server=utf8
lower_case_table_names=1
skip-grant-tables

$ vi /etc/my.cnf.d/client.cnf
[client]
default-character-set=utf8

$ systemctl restart mysqld
$ mysql -uroot

Let's check the user table. Also, check the password strength setting.

> use mysql
> select user,host,plugin,authentication_string from user;
+------------------+-----------+-----------------------+-----+
| user             | host      | plugin                | authentication_string |
+------------------+-----------+-----------------------+-----+
| mysql.infoschema | localhost | caching_sha2_password | *** |
| mysql.session    | localhost | caching_sha2_password | *** |
| mysql.sys        | localhost | caching_sha2_password | *** |
| root             | localhost | mysql_native_password | *** |
+------------------+-----------+-----------------------+-----+

> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+

I weaken the password strength as follows. In the initial state, it is a mixture of uppercase letters, lowercase letters, numbers, and symbols. After that, set the password for the root account. A plain password that does not match the strength of the password will result in "ERROR 1819 (HY000): Your password does not satisfy the current policy requirements".

> set global validate_password.length=6; 
> set global validate_password.policy=LOW;
> set global validate_password.special_char_count=0;
> flush privileges;

> alter user 'root'@'localhost' identified by '***';   #With any password
> flush privileges;
> exit;

Remove skip-grant-tables, reboot and make sure you can log in with the root account.

$ vi /etc/my.cnf.d/mysql-server.cnf
[mysqld]
character-set-server=utf8
lower_case_table_names=1
#skip-grant-tables            #Comment out

$ systemctl restart mysqld
$ mysql -uroot -p mysql
Enter password: ***

(5) Set GRANT by create database and create user

Create the required user-defined database and account and set GRANT. In the example below, the kankeri and xxx databases. For the kankeri database, we have GRANTed accounts kadmin and kuser. Password strength is the same as root described above.

> use mysql;
> create database kankeri;
> create database xxx;

> CREATE USER kadmin@localhost IDENTIFIED BY '***'; 
> CREATE USER kuser@localhost  IDENTIFIED BY '***';   

> GRANT ALL PRIVILEGES ON kankeri.* TO kamin@localhost;            
> GRANT DELETE,INSERT,SELECT,UPDATE ON kankeri.* TO kuser@localhost;  
> flush privileges;
> select user,host,plugin,authentication_string from user;
+------------------+-----------+-----------------------+-----+
| user             | host      | plugin                | authentication_string |
+------------------+-----------+-----------------------+-----+
| kadmin           | localhost | mysql_native_password | *** |
| kuser            | localhost | mysql_native_password | *** |
| mysql.infoschema | localhost | caching_sha2_password | *** |
| mysql.session    | localhost | caching_sha2_password | *** |
| mysql.sys        | localhost | caching_sha2_password | *** |
| root             | localhost | mysql_native_password | *** |
+------------------+-----------+-----------------------+-----+

(6) Restore from the dump.

Restore the files backed up in the first step (1) and restore the data.

$ mysql -uroot -p kankeri < /var/tmp/dump-kankeri.sql
$ mysql -uroot -p xxx     < /var/tmp/dump-xxx.sql

$ mysql -ukuser -p kankeri
Enter password: ***
> show tables;

that's all

../

Recommended Posts

Procedure to change lower_case_table_names = 1 in MySQL 8.0 of CentOS 8.3
[Rails5.2] Support for emoji of Mysql 5.7 in Docker (change character code to utf8mb4)
When you want to change the MySQL password of docker-compose
How to change BackgroundColor etc. of NavigationBar in Swift UI
802.1X authentication to the network of Bonding setting in CentOS7
Upgrade from MYSQL5.7 to 8.0 on CentOS 6.7
Steps to install MySQL 8 on CentOS 8
Change DB from SQLite to MySQL
I want to change the value of Attribute in Selenium of Ruby
How to change app name in rails
Procedure to make the value of the property file visible in Spring Boot
How to use MySQL in Rails tutorial
Change List <Optional <T >> to Optional <List <T >> in Java
How to change the maximum and maximum number of POST data in Spark
How to change the value of a variable at a breakpoint in intelliJ
Japanese setting of mysql in Docker container
Change the save destination of the image to S3 in the Rails app. Part 2
[Swift] How to change the order of Bar Items in Tab Bar Controller [Beginner]
Sample code to get the values of major SQL types in Java + MySQL 8.0
Summary of how to select elements in Selenium
Procedure for loading JDBC of MySQL using JAVA-Eclipse
Change the timezone of the https-portal container to JST
How to use JQuery in js.erb of Rails6
Support out of support in docker environment using centos6
DataSource connection from WebSphere to MySQL (DataSource property change?)
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
Stumble in MySQL 5.5-> 5.7
Change date and time to Japanese notation in Rails
Change the database (MySQL) primary key to any column.
Understand the characteristics of Scala in 5 minutes (Introduction to Scala)
How to install the root certificate of Centos7 (Cybertrust)
[Rails] How to change the column name of the table
Procedure to use S3 of LocalStack for Active Storage
How to use CommandLineRunner in Spring Batch of Spring Boot
Change the storage quality of JPEG images in Java
Install MySQL 5.6 on CentOS6 [How to specify the version]
Summary of how to implement default arguments in Java
[Ruby on Rails] From MySQL construction to database change
I want to change the color of the upper control navigation bar (Control menu) in Liferay 7 / DXP