1 Background introduction
Since business requirements require the localization of the database, the data is migrated from the mysql database to the domestic Dameng database. Migrate each library in mysql to different modes of Dameng. The following is the detailed process.
2 specific steps
(1) Install Dameng client tool
(2) Click to select the DM management tool
(3) Create schema and user
In the user menu, create a new TEST mode and the corresponding user.
(4) Open the DM migration tool
(5) Create a project
Right-click the blank space in the DM migration tool and create a project named mysql
(6) Create a migration task
Click on the newly created mysql project, right-click to migrate, and create a new migration task mysqltransfer
(7) Configure mysql source
Add the ip, port, username and password of mysql in turn.
(8) Configure Dameng database information
Add the ip, port, user name and password of Dameng data in turn, and select the TEST user at this time.
Select the target mode as TEST mode, click Next
Select all database tables, click Next
(9) Execute the migration task
Click the Finish button to start the database migration. Since the data types of mysql and Dameng data are not completely consistent, the migration may fail, and a log will be generated, and the corresponding problems can be modified according to the log.
(10) Common problems in migration
When the time type of TIMESTAMP
mysql can be set to ON UPDATE CURRENT_TIMESTAMP, the field can be automatically refreshed when the data is updated;
Dameng database does not have the ON UPDATE CURRENT_TIMESTAMP type, but triggers can be created to complete similar operations, and the underlying layer of mysql should also be The triggers taken implement this event type.
Related to geometry type
- The geometry type needs to be initialized when using the geometry type for the first time in the Dameng database, otherwise an error will be reported as the invalid data type in the setting field as the geometry type.
Geometry initialization steps:
- Log in to the SQL client as the database administrator, and use the following command to initialize the geometry type:
- SP_INIT_GEO_SYS(1);
- Confirm that the geometry type is initialized by issuing the following SQL command: SELECT SF_CHECK_GEO_SYS;
- If the geometry type is initialized, the command will return the following:
LINES | SF_CHECK_GEO_SYS |
---|---|
1 | 1 |
- The geometry type of Dameng data is st_geometry, and st_geometry must be filled in when creating a table and filling in the type
- When the table data exported from mysql contains the geometry type, the system will export the format as ST_GeomFromText (field), and when importing it into the dream database, it needs to be modified to DMGEO.ST_GEOMFROMTEXT (field, 0)
Questions about Chinese characters
LENGTH_IN_CHAR=0 varchar is in bytes, a Chinese character in gb18030 is two bytes, a Chinese character in utf-8 is generally three bytes
LENGTH_IN_CHAR=1 The number of bytes stored in varchar will be according to A certain proportion of expansion, the number of bytes of varchar is equal to the defined length *
2 when gb18030, and the number of bytes of varchar is the defined length *
4
when the character set is utf-8. When it is found that the imported data exceeds the character range, the field length can be modified appropriately
Table field type modification
Since there are no longtext and JSON types in Dameng, it is necessary to change longtext to LONGVARCHAR, and JSON type to varchar, varchar2, char, clob, etc. as the data type of the storage field.
A lock timeout occurs in the database,
and a session with a lock is detected
select a.*,b.NAME,c.SESS_ID from v$lock a
left join sysobjects b on b.ID=a.TABLE_ID
left join v$sessions c on a.TRX_ID=c.TRX_ID;
Close the corresponding lock according to session_id
sp_close_session(sess_id);