|
上篇(7 巨杉數(shù)據(jù)庫SequoiaDB手動(dòng)創(chuàng)建集群)介紹了如何手動(dòng)創(chuàng)建集群,下面將在上篇的基礎(chǔ)上將介紹如何手工創(chuàng)建MySQL實(shí)例。
1 部署架構(gòu)
本實(shí)驗(yàn)Sequoia DB巨杉數(shù)據(jù)庫集群拓?fù)浣Y(jié)構(gòu)為單副本三分區(qū),包括1個(gè)SequoiaSQL-MySQL數(shù)據(jù)庫實(shí)例節(jié)點(diǎn)、1個(gè)存儲(chǔ)引擎節(jié)點(diǎn)、1個(gè)編目節(jié)點(diǎn)和3個(gè)數(shù)據(jù)節(jié)點(diǎn)。

2 手工創(chuàng)建MySQL實(shí)例
2.1 安裝SequoiaSQL-MySQL實(shí)例
[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 通用公共授權(quán)
第二版, 1991年6月
著作權(quán)所有 (C) 1989,1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
允許每個(gè)人復(fù)制和發(fā)布本授權(quán)文件的完整副本,但不允許對它進(jìn)行任何修改。
[1] 同意以上協(xié)議: 了解更多的協(xié)議內(nèi)容,可以在安裝后查看協(xié)議文件
[2] 查看詳細(xì)的協(xié)議內(nèi)容
請選擇一個(gè)選項(xiàng) [1] :
----------------------------------------------------------------------------
請指定 SequoiaSQL MySQL Server 將會(huì)被安裝到的目錄
安裝目錄 [/opt/sequoiasql/mysql]:
----------------------------------------------------------------------------
數(shù)據(jù)庫管理用戶配置
配置用于啟動(dòng)SequoiaSQL-MySql的用戶名、用戶組和密碼
用戶名 [sdbadmin]:
用戶組 [sdbadmin_group]:
密碼 [********] :
確認(rèn)密碼 [********] :
----------------------------------------------------------------------------
設(shè)定現(xiàn)在已經(jīng)準(zhǔn)備將 SequoiaSQL MySQL Server 安裝到您的電腦.
您確定要繼續(xù)? [Y/n]:
----------------------------------------------------------------------------
正在安裝 SequoiaSQL MySQL Server 于您的電腦中,請稍候.
安裝中
0% ______________ 50% ______________ 100%
#########################################
----------------------------------------------------------------------------
安裝程序已經(jīng)完成安裝 SequoiaSQL MySQL Server 于你的電腦中.
2.2 創(chuàng)建MySQL實(shí)例
1)切換至sdbadmin用戶
[root@sdbserver1 sequoiadb-3.4]# su - sdbadmin
2)創(chuàng)建myinst實(shí)例
[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)查看實(shí)例
[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 驗(yàn)證MySQL實(shí)例
3.1 連接MySQL實(shí)例
[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 創(chuàng)建數(shù)據(jù)庫和表
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 數(shù)據(jù)操作
1)查看表結(jié)構(gòu)
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
由此可見,創(chuàng)建的表默認(rèn)為SEQUOIADB存儲(chǔ)引擎。
2)插入數(shù)據(jù)
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)查看數(shù)據(jù)
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 存儲(chǔ)引擎層操作數(shù)據(jù)
1)連接SDB和查看數(shù)據(jù)
[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)插入數(shù)據(jù)
> db.test.emp.insert({empno:4,ename:'Jack',age:35})
{
"InsertedNum": 1,
"DuplicatedNum": 0
}
Takes 0.000798s.
直接在存儲(chǔ)引擎層操作的數(shù)據(jù),會(huì)映射在數(shù)據(jù)庫實(shí)例層。
|