Problems and solutions when replacing Oracle with MySQL

Problems and solutions when replacing Oracle with MySQL

Migration Tools

During testing, powerdesinger was used to convert the table structure and Navicat was used to import data. The amount of data in the production environment is large, and colleagues in the data group will choose other tools to migrate it and supplement it when the time comes.

Application transformation

Add mysql8.0 driver package

Use mysql-connector-java-8.0.15.jar. If it is managed by Maven, add dependencies directly:

                <!--MySql Driver-->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.15</version>
			<scope>runtime</scope>
		</dependency>

Modify data source configuration

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://host:ip/database?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=password

Object transformation

  • If you use hibernate, delete the auto-increment sequence of the primary key in the configuration file, set the primary key to auto-increment in MySQL; or create a corresponding function for the sequence. If you use MySQL cluster, the way the primary key is generated will change.
  • Check each sql statement, especially the sql statements spliced ​​in mybatis, including:
    • Primary key modification: delete the sequence, change the primary key in the database to auto-increment; or create a corresponding auto-increment function
    • To process the fields involving mysql keywords, use the `` identifier
    • Date format handling
    • Change rownum condition query to limit condition query

Problem Summary

Problem: Local remote connection to MySQL database, report 10060 login exception

  • Possible reasons for this problem:

1. The network is not accessible; 2. The service is not started; 3. The firewall is not closed; 4. The firewall port on the server is not open; 5. The port is not being monitored; 6. Insufficient permissions. I am here to troubleshoot and find out why port 3306 on the test database server is not open.

  • Solution:
sudo vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
sudo service iptables restart
sudo iptables -L -n

Problem: Navicat connecting to MySQL8 results in 2059 error

  • Reason: The encryption rule in versions before mysql8 is mysql_native_password, and after mysql8, the encryption rule is caching_sha2_password
  • Solution: Change the encryption rules
mysql -uroot -ppassword #Loginuse mysql; #Select databaseALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #Change encryption methodALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; #Update user passwordFLUSH PRIVILEGES; #Refresh permissions

Problem: Using Navicat to migrate data reports an error --> [Err] [Dtf] 1426 - Too-big precision 7 specified for 'TIME_CREATE'. Maximum is 6.

  • Reason: Oracle's DATE type is 7 digits, while MySQL's time type is at most 6 digits, so it cannot be imported.
  • Solution: Change DATE in the Oracle database to TIMESTAMP and change the length to 6 (be sure to change both the type and length before saving), then you can import.

Problem: Error when inserting varchar field during data migration --> Data too long for column 'DESIGNER' at row 1

  • Reason: Oracle and MySQL use different encoding sets, resulting in different storage length requirements for the same characters (further in-depth understanding is required)
  • Solution: You need to extend the field length in msyql

Problem: SpringBoot connects to MySQL and reports an error --> Unknown system variable 'query_cache_size'

  • Reason: The MySQL driver jar package version is too low and is not compatible with MySQL 8.0.
  • Solution: Use mysql-connector-java-8.0.15.jar and change the driver name to com.mysql.cj.jdbc.Driver

Problem: After changing to MySQL, the Chinese characters displayed in the front-end page of the application are garbled.

  • Cause: Check the encoding format from three dimensions: database, server, and page
    • MySQL database encoding format check
    • Check the server encoding format
    • Front-end page coding format check

Finally, it was discovered that the encoding format was set to utf-8 in the Navicat connection, which caused the imported data to appear normal in Navicat, but garbled in the database and the query results. I really checked this for a long time, but I didn't notice the reason for the tool. .

  • Solution: Reset the encoding format, import the data, and display it normally.

The above are the details of the problems encountered and solutions when switching from Oracle to MySQL. For more information about switching from Oracle to MySQL, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Common writing examples for MySQL and Oracle batch insert SQL
  • MySQL to Oracle real-time data synchronization

<<:  JavaScript Basics Variables

>>:  VMware ESXI server virtualization cluster

Recommend

Example of how to use CSS3 to layout elements around a center point

This article introduces an example of how CSS3 ca...

A Deeper Look at the Differences Between Link and @import

There are three main ways to use CSS in a page: ad...

Example of how to build a Harbor public repository with Docker

The previous blog post talked about the Registry ...

Steps to modify the MySQL database data file path under Linux

After installing the MySQL database using the rpm...

Faint: "Use web2.0 to create standard-compliant pages"

Today someone talked to me about a website develo...

How to install mysql via yum on centos7

1. Check whether MySQL is installed yum list inst...

A brief discussion on spaces and blank lines in HTML code

All consecutive spaces or blank lines (newlines) ...

In-depth explanation of the locking mechanism in MySQL InnoDB

Written in front A database is essentially a shar...

Sample code for partitioning and formatting a disk larger than 20TB on centos6

1. Server environment configuration: 1. Check dis...

TypeScript Enumeration Type

Table of contents 1. Overview 2. Digital Enumerat...

The leftmost matching principle of MySQL database index

Table of contents 1. Joint index description 2. C...