How to Create a GBase 8s Database with a Non-Default Character Set

Published on 2020-11-19

Introduction

Many beginners using GBase 8s encounter errors when inserting or loading data into tables, or see garbled characters when querying table data, because they overlooked the database character set.

In such cases, the only solution is to create a new database and make sure its character set matches that of the data. For example, if the original database testdb uses UTF8 but the table data is in GBK, loading the data will fail. You need to create a new database that supports the GBK character set, create the tables there, and then import the data.

Below we illustrate how to create a database with a non-default character set using two methods: the Enterprise Manager tool (GBaseDataStudio.exe) and the dbaccess command.

The content of this article was tested in the following environment:

Database version: GBase8s V8.8_TL_3.0.0

Enterprise Manager: GBaseDataStudio_8.5.21.0

Related keywords: GBase 8s, create database, character set

 

1. Enterprise Manager Steps

The Enterprise Manager is the GBase graphical client and can run on Windows or Linux.
 

To create a new database with the GB18030 character set (a variant of the GBK character set) using the Enterprise Manager, follow these steps:

1. View the original character set of the database.

2. Disconnect from the database, create a new connection, set the character set parameters to GB18030, and connect.

3. Create a new database.

Step 1: View the original character set of the database

In the left tree of the Enterprise Manager, locate the database testdb and double-click it. The testdb window appears on the right. Check the "Collation" field; it indicates that the database character set is zh_CN.57372 (which represents the UTF8 character set).

Step 2: Disconnect, create a new connection, set character set parameters, and reconnect to the database
 


 

Right-click the Data Connection in the left tree of the Enterprise Manager, and select "Disconnect" from the pop-up menu to disconnect from the database.


 

Right-click the Data Connection again and select "Edit Connection" to configure.
 

 

 

In the "Connection Configuration" dialog, set "Database/Schema" to the system database sysmaster, which can connect regardless of any character set.

 

Click "Driver Properties" on the left, set the character set parameters CLIENT_LOCALE and DB_LOCALE to zh_cn.GB18030-2000 (representing the GBK character set).
 

 

 

Click "OK" to finish.

Right-click the Data Connection again, select "Connect" from the pop-up menu, and you will be reconnected to the database.

Step 3: Create a new database

Click "Databases" in the left tree of the Enterprise Manager, right-click and select "New Database" from the pop-up menu. The "Create Database" window appears.


 

 

Enter the database name, the storage location (dbspace name), and choose a logging mode (buffered logging, unbuffered logging, or no logging), then click "OK" to create the database.

All tables created under this database will use the GB18030 character set.

 

2. dbaccess Steps

dbaccess is the command-line client tool included with GBase 8s, and it runs on Linux.
 

To create a new database with the GB18030 character set (a variant of the GBK character set) using dbaccess, follow these steps:

1. Set the character set parameters in the environment variables.

2. Make the environment variables take effect.

3. Use dbaccess to create the database.

Step 1: Set character set parameters in environment variables

In the environment configuration file .bash_profile of the database user gbasedbt, add the character set environment variables DB_LOCALE and CLIENT_LOCALE while preserving existing variables:

export DB_LOCALE=zh_cn.GB18030-2000

export CLIENT_LOCALE=zh_cn.GB18030-2000 

Step 2: Make the environment variables take effect
 

[gbasedbt@node176 ~]$ source .bash_profile 

Step 3: Create a database using dbaccess

Connect to the database using dbaccess and create a new database db_18030 with SQL:

[gbasedbt@node176 ~]$ dbaccess - - 

create database db_18030 in rootdbs with log;

The database is created successfully. All tables created under it will use the GB18030 character set.
 

That's all for this sharing.