Table of Contents
Modifying Data Through a View
Home Database Mysql Tutorial MySQL to GBase Migration Guide

MySQL to GBase Migration Guide

Jul 17, 2024 am 05:58 AM

MySQL to GBase Migration Guide

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 (https://dev.mysql.com/doc/) and the GBase 8c user manual. Due to the extensive content involved in 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, 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
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
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:

(1) 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.

(2) 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.

(3) CREATE TABLE LIKEAS
GBase 8c also supports the CREATE TABLE LIKEAS 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
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;
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;
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;
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.

The above is the detailed content of MySQL to GBase Migration Guide. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

See all articles