上篇(​​7 巨杉数据库SequoiaDB手动创建集群​​)介绍了如何手动创建集群,下面将在上篇的基础上将介绍如何手工创建MySQL实例。

1 部署架构

本实验Sequoia DB巨杉数据库集群拓扑结构为单副本三分区,包括1个SequoiaSQL-MySQL数据库实例节点、1个存储引擎节点、1个编目节点和3个数据节点。

【SequoiaDB】8 巨杉数据库SequoiaDB手动创建MySQL实例_MySQL

2 手工创建MySQL实例

2.1 安装SequoiaSQL-MySQL实例

[root@sdbserver1 sequoiadb-3.4]# ./sequoiasql-mysql-3.4-linux_x86_64-installer.run --mode text

Language Selection



Please select the installation language

[1] English - English

[2] Simplified Chinese - 简体中文

Please choose an option [1] : 2

----------------------------------------------------------------------------

由BitRock InstallBuilder评估本所建立



欢迎来到 SequoiaSQL MySQL Server 安装程序



----------------------------------------------------------------------------

GNU 通用公共授权

第二版, 1991年6月

著作权所有 (C) 1989,1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

允许每个人复制和发布本授权文件的完整副本,但不允许对它进行任何修改。



[1] 同意以上协议: 了解更多的协议内容,可以在安装后查看协议文件

[2] 查看详细的协议内容

请选择一个选项 [1] :



----------------------------------------------------------------------------

请指定 SequoiaSQL MySQL Server 将会被安装到的目录



安装目录 [/opt/sequoiasql/mysql]:



----------------------------------------------------------------------------

数据库管理用户配置



配置用于启动SequoiaSQL-MySql的用户名、用户组和密码



用户名 [sdbadmin]:



用户组 [sdbadmin_group]:



密码 [********] :

确认密码 [********] :

----------------------------------------------------------------------------

设定现在已经准备将 SequoiaSQL MySQL Server 安装到您的电脑.



您确定要继续? [Y/n]:



----------------------------------------------------------------------------

正在安装 SequoiaSQL MySQL Server 于您的电脑中,请稍候.



安装中

0% ______________ 50% ______________ 100%

#########################################



----------------------------------------------------------------------------

安装程序已经完成安装 SequoiaSQL MySQL Server 于你的电脑中.


2.2 创建MySQL实例

1)切换至sdbadmin用户

[root@sdbserver1 sequoiadb-3.4]# su - sdbadmin


2)创建myinst实例

[sdbadmin@sdbserver1 ~]$ cd /opt/sequoiasql/mysql/

[sdbadmin@sdbserver1 mysql]$ bin/sdb_sql_ctl addinst myinst -D database/3306

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

Adding instance myinst ...

Start instance myinst ...

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

ok


3)查看实例

[sdbadmin@sdbserver1 mysql]$ bin/sdb_sql_ctl status

INSTANCE PID SVCNAME SQLDATA SQLLOG

myinst 4461 3306 /opt/sequoiasql/mysql/database/3306 /opt/sequoiasql/mysql/myinst.log

Total: 1; Run: 1

[sdbadmin@sdbserver1 mysql]$ bin/sdb_sql_ctl listinst

NAME SQLDATA SQLLOG

myinst /opt/sequoiasql/mysql/database/3306 /opt/sequoiasql/mysql/myinst.log

Total: 1


4)查看配置文件

[sdbadmin@sdbserver1 mysql]$ cat database/3306/auto.cnf

[auto]

server-uuid=99a4fc85-742b-11ea-8874-080027f936eb

[client]

default_character_set=utf8mb4



[mysqld]

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

character_set_server=utf8mb4

collation_server=utf8mb4_bin

default_storage_engine=SequoiaDB



# Overhead threshold of table alteration. When count of records exceeds it, the alteration that needs to update the full table will be prohibited.

# sequoiadb_alter_table_overhead_threshold=10000000



# Automatically create partition table on SequoiaDB.

# sequoiadb_auto_partition=ON



# Maximum number of records per bulk insert.

# sequoiadb_bulk_insert_size=2000



# SequoiaDB addresses.

# sequoiadb_conn_addr=localhost:11810



# Turn on debug log of SequoiaDB storage engine.

# sequoiadb_debug_log=OFF



# Sequoiadb error level for updating sharding key error.

# sequoiadb_error_level=error



# Commands execute only in mysql.

# sequoiadb_execute_only_in_mysql=OFF



# Optimizer_options[=option[,option...]], where option can be 'direct_count', 'direct_delete', 'direct_update'.direct_count: use count() instead of reading records one by one for count queries. direct_delete: direct delete without reading records.direct_update: direct update without reading records.

# sequoiadb_optimizer_options=direct_count,direct_delete,direct_update



# SequoiaDB authentication password.

# sequoiadb_password=



# Replica size of write operations.

# sequoiadb_replica_size=1



# The threshold of selector push down to SequoiaDB.

# sequoiadb_selector_pushdown_threshold=30



# Enable autocommit of SequoiaDB storage engine.

# sequoiadb_use_autocommit=ON



# Enable bulk insert to SequoiaDB.

# sequoiadb_use_bulk_insert=ON



# Enable transaction of SequoiaDB.

# sequoiadb_use_transaction=ON



# SequoiaDB authentication user.

# sequoiadb_user=



port=3306

basedir=/opt/sequoiasql/mysql

datadir=/opt/sequoiasql/mysql/database/3306

pid-file=/opt/sequoiasql/mysql/database/3306/mysqld.pid

log_error=/opt/sequoiasql/mysql/myinst.log

socket=/opt/sequoiasql/mysql/database/3306/mysqld.sock


3 验证MySQL实例

3.1 连接MySQL实例

[sdbadmin@sdbserver1 mysql]$ bin/mysql -h 127.0.0.1 -uroot

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.25 Source distribution



Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.



Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.



Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



mysql>


3.2 创建数据库和表

mysql> create database test;

Query OK, 1 row affected (0.00 sec)



mysql> use test;

Database changed

mysql> create table emp(empno int auto_increment primary key,ename varchar(200),age int);

Query OK, 0 rows affected (0.87 sec)


3.3 数据操作

1)查看表结构

mysql> show create table emp\G;

*************************** 1. row ***************************

Table: emp

Create Table: CREATE TABLE `emp` (

`empno` int(11) NOT NULL AUTO_INCREMENT,

`ename` varchar(200) COLLATE utf8mb4_bin DEFAULT NULL,

`age` int(11) DEFAULT NULL,

PRIMARY KEY (`empno`)

) ENGINE=SEQUOIADB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

1 row in set (0.01 sec)



ERROR:

No query specified


由此可见,创建的表默认为SEQUOIADB存储引擎。

2)插入数据

mysql> insert into emp(ename,age) values('Alen',23),('Lucy',25),('Tom',30);

Query OK, 3 rows affected (0.01 sec)

Records: 3 Duplicates: 0 Warnings: 0


3)查看数据

mysql> select * from emp;

+-------+-------+------+

| empno | ename | age |

+-------+-------+------+

| 1 | Alen | 23 |

| 2 | Lucy | 25 |

| 3 | Tom | 30 |

+-------+-------+------+

3 rows in set (0.00 sec)


3.4 存储引擎层操作数据

1)连接SDB和查看数据

[sdbadmin@sdbserver1 mysql]$ sdb

Welcome to SequoiaDB shell!

help() for help, Ctrl+c or quit to exit

> var db=new Sdb('localhost',11810)

Takes 0.005398s.

> db.test.emp.find()

{

"_id": {

"$oid": "5e84b1d4354e2e0d13d357e6"

},

"ename": "Alen",

"age": 23,

"empno": 1

}

{

"_id": {

"$oid": "5e84b1d4354e2e0d13d357e7"

},

"ename": "Lucy",

"age": 25,

"empno": 2

}

{

"_id": {

"$oid": "5e84b1d4354e2e0d13d357e8"

},

"ename": "Tom",

"age": 30,

"empno": 3

}

Return 3 row(s).

Takes 0.012692s


2)插入数据

> db.test.emp.insert({empno:4,ename:'Jack',age:35})

{

"InsertedNum": 1,

"DuplicatedNum": 0

}

Takes 0.000798s.


直接在存储引擎层操作的数据,会映射在数据库实例层。