mysql migration record
background
The company has built its own PAAS platform, which can support the CI/CD process. Our release process is mit->test->uat->prod. Corresponding to development, testing, acceptance, and production environments respectively, and the environments are isolated from each other.
There is a historical database only available in the TEST environment. In order to facilitate debugging, you need to copy a copy to the MIT environment. The following is a record of the problems encountered.
Safe and reliable data migration method
tool
Recommended articles: https://www.cnblogs.com/swtjavaspace/p/9698167.html
navicat using Tools -> Data transmission can easily put one machine to another machine database synchronization (and including data structures)
Encounter problems
Got a packet bigger than ‘max_allowed_packet’ bytes With statement
If the content of a database table is too large, it will fail. At this time, you can modify the database configuration.
vim /etc/my.conf # windows下是my.ini
# [mysqld]下加入一行 注意是mysqld
max_allowed_packet=16M
systemctl restart mariadb # 然后重启mysql
Restart mysql
systemctl restart mariadb
Execute the statement to see if it takes effect:
MariaDB [(none)]> show VARIABLES like '%max_allowed_packet%';
+--------------------------+------------+
| Variable_name | Value |
+--------------------------+------------+
| max_allowed_packet | 16777216 |
| slave_max_allowed_packet | 1073741824 |
+--------------------------+------------+
2 rows in set (0.00 sec)
16777216 represents 16M, and the default is 1024.
Invalid default value for'CREATE_TIME' error solution
A field in the source table is of the datetime type, and the default value uses CURRENT_TIMESTAMP to generate the default time. An error was reported when importing. According to online information, this function needs to be supported by mysql5.7 or higher:
View mysql version
[root@10-0-59-117 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 253
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Option 1: Upgrade mysql 5.7 and above.
Solution 2: Modify the default value CURRENT_TIMESTAMP to NULL.
Option three: skip.
Because some tables are not practical, so I chose option 3, and skipped the error-reporting tables when transferring data. If necessary later, manually export and import to make corrections.
Reference:
https://www.jianshu.com/p/2f30786a5a6a
https://www.cnblogs.com/han-1034683568/p/11418264.html
Ignore case of table names
dos't not exist bi_sqa.sys_log
After the migration is complete, start the service and prompt that the table name does not exist. After checking the code found inside using uppercase table name , and in Linux mysql is not enabled by default ignores the table name case sensitivity feature.
In mysql.conf the mysqld adding the following configuration, can then restart mysql.
[mysqld]
lower_case_table_names=1
Check whether it works
MariaDB [(none)]> show variables like "%case%";
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
2 rows in set (0.00 sec)
If 1 is displayed , it means it is Ok.
It is recommended to use lowercase table names
If you enable lower_case_table_names , the system using all lowercase table names, if appears uppercase table name, you will be prompted non-existent problem.
Therefore, if there are many system modules, involving multiple development languages (C++/JAVA), etc., it is recommended to use lowercase table names to avoid some problems in advance.