DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Recover Distributed Transactions in MySQL
  • Enhancing Database Efficiency With MySQL Views: A Comprehensive Guide and Examples
  • Seamless Transition: Strategies for Migrating From MySQL to SQL Server With Minimal Downtime
  • How To Convert MySQL Database to SQL Server

Trending

  • Understanding and Mitigating IP Spoofing Attacks
  • Using Python Libraries in Java
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  • Teradata Performance and Skew Prevention Tips
  1. DZone
  2. Data Engineering
  3. Databases
  4. MySQL to GBase 8C Migration Guide

MySQL to GBase 8C Migration Guide

This article provides a quick guide for migrating application systems based on MySQL databases to GBase databases (GBase 8c).

By 
Cong Li user avatar
Cong Li
·
Jun. 26, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
2.2K Views

Join the DZone community and get the full member experience.

Join For Free

This article provides a quick guide for migrating application systems based on MySQL databases to GBase databases (GBase 8c). For detailed information about specific aspects of both databases, readers can refer to the MySQL official documentation and the GBase 8c user manual. Due to the extensive content involved in the basic mapping of MySQL data types and other aspects of the migration process, this will not be covered in detail in this article. If interested, please leave a comment, and we can discuss it next time.

1. Creating a Database

In both MySQL and GBase 8c, the CREATE DATABASE statement is used to create a database. The specific syntax differences are as follows:

Operation MySQL SQL Statement GBase 8c SQL Statement
CREATE DATABASE CREATE DATABASE example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE DATABASE example OWNER gbase ENCODING ‘UTF8’ LC_COLLATE 'en_US.UTF-8'  LC_CTYPE 'en_US.UTF-8';


Considerations for Migrating SQL Statements for Creating Databases

1. In both MySQL and GBase 8c, you can specify the character set and collation rules when creating a database.

Unlike MySQL, in GBase 8c, the ENCODING keyword is used to specify the character set and the LC_COLLATE and LC_CTYPE keywords are used to specify collation rules:

  • LC_COLLATE: This parameter affects the sorting order of strings (e.g. when using ORDER BY, as well as the order of indexes on text columns).
  • LC_CTYPE: This parameter affects character classification, such as uppercase, lowercase, and digits.

2. When creating a database in GBase 8c, you can also specify unique additional attributes. Common attributes include.

  • OWNER: This parameter specifies the owner of the database. If not specified, the owner defaults to the current user.
  • CONNECTION LIMIT: This parameter specifies the number of concurrent connections the database can accept. System administrators are not subject to this limit.

3. Database Structure

In MySQL, database and schema are synonymous, and databases can reference each other. In GBase 8c, the database and schema are distinct objects. A single database can contain multiple schemas, and databases cannot reference each other, but schemas within the same database can.

2. Using the Database

Comparison of various SQL statements for operating the database:

Operation MySQL SQL Statement GBase 8c SQL Statement GBase 8c gsql Tool
View Databases SHOW DATABASES; or SHOW DATABASE example; SELECT * FROM pg_database; \l or \l+
Switch Database USE example; Reconnect to switch, this function does not use SQL to switch \c example
Delete Database DROP DATABASE example; DROP DATABASE example; None


3. Creating Tables

Both MySQL and GBase 8c support creating tables using the CREATE TABLE statement. The specific syntax differences are as follows:

Operation MySQL SQL Statement GBase 8c SQL Statement
Creating Tables using CREATE TABLE CREATE TABLE `my_table` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'id',
`user_id` int NOT NULL COMMENT 'User id',
`name` varchar(50) DEFAULT NULL COMMENT 'Name',
`address` varchar(50) DEFAULT NULL COMMENT 'Address',
`password` varchar(20) DEFAULT 'passwd' COMMENT 'Password',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE "my_table" (
"id" SERIAL NOT NULL,
"user_id" int NOT NULL,
"name" varchar(50),
"address" varchar(50),
"passwd" varchar(20) DEFAULT 'password',
CONSTRAINT "my_table_pkey" PRIMARY KEY ("id")
);

COMMENT ON COLUMN "my_table"."id" IS 'id';
COMMENT ON COLUMN "my_table"."user_id" IS 'User id';
COMMENT ON COLUMN "my_table"."name" IS 'Name';
COMMENT ON COLUMN "my_table"."address" IS 'Address';
COMMENT ON COLUMN "my_table"."passwd" IS 'Password';
Creating Tables using CREATE TABLE ... LIKE create table `my_table_like` like `my_table`; create table my_table_like (like my_table);
Creating Tables using CREATE TABLE ... AS create table `my_table_as` as select * from `my_table`; create table my_table_as as select * from my_table ;


When migrating SQL statements for creating tables, the following syntax changes are required:

Naming Rules and Case Sensitivity 

In MySQL, database, table, and field names are enclosed in backticks (``) for marking. This is not allowed in GBase 8c; instead, GBase 8c uses either double quotes or no marks at all.

In GBase 8c, if table and field names are not enclosed in double quotes, they are automatically converted to lowercase when the table is created. If you need to specify uppercase names, you must enclose the names in double quotes.

Storage Engine-Related Changes

  • When migrating to GBase 8c, you need to remove storage engine-related clauses such as ENGINE and TYPE from MySQL statements.
  • GBase 8c does not support setting character sets at the table level, so CHARSET clauses in MySQL statements should be removed when migrating to GBase 8c.

CREATE TABLE LIKE\AS

GBase 8c also supports the CREATE TABLE LIKE\AS syntax, but the usage of the LIKE clause differs from MySQL. In GBase 8c, the LIKE clause must be enclosed in "()", and it does not automatically copy the COMMENT annotations from the original table columns.

4. View-Related Statements

Both MySQL and GBase 8c support views and the basic creation method is similar. However, it is important to note that in GBase 8c, under the default rule, directly modifying data in a view is not supported.

Operation MySQL SQL Statement GBase 8c SQL Statement
Creating a View CREATE VIEW v_my_table AS SELECT * FROM my_table; CREATE VIEW v_my_table AS SELECT * FROM my_table;
Modifying Data Through a View INSERT INTO v_my_table(user_id, name, address) VALUES(2222, 'bbb', 'xxxx'); Supported, but requires adjusting the default RULE
Dropping a View DROP VIEW v_my_table; DROP VIEW v_my_table;


5. Index-Related Statements

Both MySQL and GBase 8c support indexing functionality, but there are slight differences in the creation and deletion operations. The basic syntax differences are as follows:

Operation MySQL SQL Statement GBase 8c SQL Statement
Creating Index CREATE INDEX i_user_id USING BTREE ON my_table (user_id);
or
CREATE INDEX i_user_id ON my_table (user_id) USING BTREE;
CREATE INDEX i_user_id ON my_table USING BTREE (user_id);
Dropping Index DROP INDEX i_user_id ON my_table; DROP INDEX i_user_id;


Attention Points for Migrating Index Creation and Deletion Statements

1. Position of USING index_type In MySQL, the USING index_type clause can appear either before or after the table_name(col_name) clause, as shown:

... USING index_type table_name(col_name) ...

OR

... table_name(col_name) USING index_type ...

However, in GBase 8c, the USING index_type clause must be placed in the middle of the table_name(col_name) clause:

... table_name USING index_type (col_name) ...

2. DROP INDEX ON table In GBase 8c, when deleting an index object, you do not need to specify the ON table clause. This clause should be removed during migration.

3. Other Properties GBase 8c does not support FULLTEXT and SPATIAL properties when creating index objects. These properties need to be removed during migration.

Database MySQL sql

Published at DZone with permission of Cong Li. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Recover Distributed Transactions in MySQL
  • Enhancing Database Efficiency With MySQL Views: A Comprehensive Guide and Examples
  • Seamless Transition: Strategies for Migrating From MySQL to SQL Server With Minimal Downtime
  • How To Convert MySQL Database to SQL Server

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!