OceanBase数据库搭建测试

OceanBase 社区版是一款开源分布式 HTAP(Hybrid Transactional/Analytical Processing)数据库管理系统

官方文档

OceanBase docker版本搭建

下载镜像

# 下载镜像
[root@localhost ~]# docker pull oceanbase/oceanbase-ce
Using default tag: latest
latest: Pulling from oceanbase/oceanbase-ce
13add961a70d: Pull complete
c8175aff0e18: Pull complete
39c994bcc219: Pull complete
71a870d28c6f: Pull complete
Digest: sha256:6c3f458abc38a017e604af1188726174b6dc81f38c96e2869dc2cb04931a8cd8
Status: Downloaded newer image for oceanbase/oceanbase-ce:latest

启动

#启动 OceanBase 实例
# deploy mini standalone instance
[root@localhost ~]# docker run -p 2881:2881 --name obstandalone -e MINI_MODE=1 -d oceanbase/oceanbase-ce
# 查看日志
[root@localhost ~]# docker logs obstandalone | tail -1
boot success!
# 连接数据库
[root@localhost ~]# docker exec -it obstandalone ob-mysql sys # Connect to sys tenant
login as root@sys
Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487642
Server version: 5.7.25 OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)

Copyright (c) 2000, 2022, OceanBase and/or its affiliates. All rights reserved.

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

obclient [oceanbase]>

#utf8
#ue ctrl+h编辑文件
#0x0f
[root@localhost ~]# docker cp test.txt obstandalone:/tmp
#,
[root@localhost ~]# docker cp test2.txt obstandalone:/tmp

LAOD 操作

# 语法
LOAD DATA
  [/*+ parallel(N) load_batch_size(M)*/]
    INFILE 'file_name'
    [REPLACE | IGNORE]
    INTO TABLE tbl_name
    [{
    
    FIELDS | COLUMNS}
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char']
    ]
    [LINES
        [STARTING BY 'string']
        [TERMINATED BY 'string']
    ]
    [IGNORE number {
    
    LINES | ROWS}]
    [(col_name_var
        [, col_name_var] ...)]
    [SET col_name={
    
    expr | DEFAULT},
        [, col_name={
    
    expr | DEFAULT}] ...]

示例


obclient [oceanbase]> LOAD DATA INFILE '/tmp/test.txt'  INTO TABLE ocb.test FIELDS TERMINATED BY '0x0f' LINES TERMINATED BY '\n';
ERROR 1227 (42501): Access denied
obclient [oceanbase]>

#无效
set global secure_file_priv="";
#用户授权,重新登录可以执行load操作
obclient [oceanbase]> GRANT FILE ON *.* to sys@'%';
Query OK, 0 rows affected (0.024 sec)

obclient [oceanbase]> LOAD DATA INFILE '/tmp/test.txt'  INTO TABLE ocb.test FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
ERROR 1227 (42501): Access denied
obclient [oceanbase]> exit
Bye
[root@localhost ~]# docker exec -it obstandalone ob-mysql sys # Connect to the root account of a general tenant
login as root@sys
Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221488957
Server version: 5.7.25 OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)

Copyright (c) 2000, 2022, OceanBase and/or its affiliates. All rights reserved.

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

obclient [oceanbase]> LOAD DATA INFILE '/tmp/test.txt'  INTO TABLE ocb.test FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
Query OK, 3 rows affected, 3 warnings (0.011 sec)
Records: 3  Deleted: 0  Skipped: 0  Warnings: 0

obclient [oceanbase]>


obclient [oceanbase]> show variables;
+--------------------------------------+------------------------------------------------------------------------------------------------------------+
| Variable_name                        | Value                                                                                                      |
+--------------------------------------+------------------------------------------------------------------------------------------------------------+
| autocommit                           | ON                                                                                                         |
| auto_increment_cache_size            | 1000000                                                                                                    |
| auto_increment_increment             | 1                                                                                                          |
| auto_increment_offset                | 1                                                                                                          |
| binlog_row_image                     | FULL                                                                                                       |
| block_encryption_mode                | aes-128-ecb                                                                                                |
| character_set_client                 | utf8mb4                                                                                                    |
| character_set_connection             | utf8mb4                                                                                                    |
| character_set_database               | utf8mb4                                                                                                    |
| character_set_filesystem             | binary                                                                                                     |
| character_set_results                | utf8mb4                                                                                                    |
| character_set_server                 | utf8mb4                                                                                                    |
| character_set_system                 | utf8mb4                                                                                                    |
| collation_connection                 | utf8mb4_general_ci                                                                                         |
| collation_database                   | utf8mb4_general_ci                                                                                         |
| collation_server                     | utf8mb4_general_ci                                                                                         |
| concurrent_insert                    | AUTO                                                                                                       |
| connect_timeout                      | 10                                                                                                         |
| datadir                              | /root/ob/store                                                                                             |
| default_authentication_plugin        | mysql_native_password                                                                                      |
| default_password_lifetime            | 0                                                                                                          |
| disabled_storage_engines             |                                                                                                            |
| div_precision_increment              | 4                                                                                                          |
| error_count                          | 0                                                                                                          |
| error_on_overlap_time                | OFF                                                                                                        |
| explicit_defaults_for_timestamp      | ON                                                                                                         |
| foreign_key_checks                   | ON                                                                                                         |
| general_log                          | OFF                                                                                                        |
| group_concat_max_len                 | 1024                                                                                                       |
| have_openssl                         | YES                                                                                                        |
| have_profiling                       | YES                                                                                                        |
| have_ssl                             | YES                                                                                                        |
| hostname                             |                                                                                                            |
| identity                             | 0                                                                                                          |
| init_connect                         |                                                                                                            |
| interactive_timeout                  | 28800                                                                                                      |
| is_result_accurate                   | ON                                                                                                         |
| last_insert_id                       | 0                                                                                                          |
| lc_messages                          | en_US                                                                                                      |
| license                              |                                                                                                            |
| local_infile                         | ON                                                                                                         |
| lock_wait_timeout                    | 31536000                                                                                                   |
| long_query_time                      | 10                                                                                                         |
| lower_case_table_names               | 2                                                                                                          |
| max_allowed_packet                   | 4194304                                                                                                    |
| max_connections                      | 4294967295                                                                                                 |
| max_execution_time                   | 0                                                                                                          |
| max_sp_recursion_depth               | 0                                                                                                          |
| max_user_connections                 | 0                                                                                                          |
| net_buffer_length                    | 16384                                                                                                      |
| net_read_timeout                     | 30                                                                                                         |
| net_write_timeout                    | 60                                                                                                         |
| ob_bnl_join_cache_size               | 10485760                                                                                                   |
| ob_check_sys_variable                | ON                                                                                                         |
| ob_compatibility_mode                | MYSQL                                                                                                      |
| ob_create_table_strict_mode          | OFF                                                                                                        |
| ob_default_replica_num               | 1                                                                                                          |
| ob_early_lock_release                | OFF                                                                                                        |
| ob_enable_aggregation_pushdown       | ON                                                                                                         |
| ob_enable_batched_multi_statement    | OFF                                                                                                        |
| ob_enable_blk_nestedloop_join        | OFF                                                                                                        |
| ob_enable_hash_group_by              | ON                                                                                                         |
| ob_enable_index_direct_select        | OFF                                                                                                        |
| ob_enable_jit                        | OFF                                                                                                        |
| ob_enable_plan_cache                 | ON                                                                                                         |
| ob_enable_sql_audit                  | ON                                                                                                         |
| ob_enable_trace_log                  | OFF                                                                                                        |
| ob_enable_transformation             | ON                                                                                                         |
| ob_enable_transmission_checksum      | ON                                                                                                         |
| ob_enable_truncate_flashback         | OFF                                                                                                        |
| ob_interm_result_mem_limit           | 2147483648                                                                                                 |
| ob_last_schema_version               | 1658416775235592                                                                                           |
| ob_log_level                         | disabled                                                                                                   |
| ob_max_parallel_degree               | 32                                                                                                         |
| ob_org_cluster_id                    | 0                                                                                                          |
| ob_plan_cache_evict_high_percentage  | 90                                                                                                         |
| ob_plan_cache_evict_low_percentage   | 50                                                                                                         |
| ob_plan_cache_percentage             | 5                                                                                                          |
| ob_pl_block_timeout                  | 3216672000000000                                                                                           |
| ob_query_timeout                     | 10000000                                                                                                   |
| ob_read_consistency                  | STRONG                                                                                                     |
| ob_reserved_meta_memory_percentage   | 10                                                                                                         |
| ob_route_policy                      | READONLY_ZONE_FIRST                                                                                        |
| ob_sql_audit_percentage              | 3                                                                                                          |
| ob_sql_work_area_percentage          | 5                                                                                                          |
| ob_stmt_parallel_degree              | 1                                                                                                          |
| ob_tcp_invited_nodes                 | %                                                                                                          |
| ob_temp_tablespace_size_percentage   | 0                                                                                                          |
| ob_timestamp_service                 | LTS                                                                                                        |
| ob_trace_info                        |                                                                                                            |
| ob_trx_idle_timeout                  | 120000000                                                                                                  |
| ob_trx_lock_timeout                  | -1                                                                                                         |
| ob_trx_timeout                       | 100000000                                                                                                  |
| optimizer_capture_sql_plan_baselines | ON                                                                                                         |
| optimizer_use_sql_plan_baselines     | ON                                                                                                         |
| parallel_max_servers                 | 5                                                                                                          |
| parallel_servers_target              | 4                                                                                                          |
| performance_schema                   | OFF                                                                                                        |
| plugin_dir                           | ./plugin_dir/                                                                                              |
| protocol_version                     | 10                                                                                                         |
| query_cache_size                     | 1048576                                                                                                    |
| query_cache_type                     | OFF                                                                                                        |
| read_only                            | OFF                                                                                                        |
| recyclebin                           | OFF                                                                                                        |
| resource_manager_plan                |                                                                                                            |
| secure_file_priv                     | NULL                                                                                                       |
| server_id                            | 0                                                                                                          |
| session_track_schema                 | ON                                                                                                         |
| session_track_state_change           | OFF                                                                                                        |
| session_track_system_variables       | time_zone, autocommit, character_set_client, character_set_results, character_set_connection               |
| sql_auto_is_null                     | OFF                                                                                                        |
| sql_mode                             | STRICT_ALL_TABLES                                                                                          |
| sql_quote_show_create                | ON                                                                                                         |
| sql_safe_updates                     | OFF                                                                                                        |
| sql_select_limit                     | 9223372036854775807                                                                                        |
| sql_throttle_cpu                     | -1                                                                                                         |
| sql_throttle_current_priority        | 100                                                                                                        |
| sql_throttle_io                      | -1                                                                                                         |
| sql_throttle_logical_reads           | -1                                                                                                         |
| sql_throttle_network                 | -1                                                                                                         |
| sql_throttle_priority                | -1                                                                                                         |
| sql_throttle_rt                      | -1                                                                                                         |
| sql_warnings                         | OFF                                                                                                        |
| ssl_ca                               |                                                                                                            |
| ssl_capath                           |                                                                                                            |
| ssl_cert                             |                                                                                                            |
| ssl_cipher                           |                                                                                                            |
| ssl_crl                              |                                                                                                            |
| ssl_crlpath                          |                                                                                                            |
| ssl_key                              |                                                                                                            |
| system_time_zone                     | +00:00                                                                                                     |
| timestamp                            | 0                                                                                                          |
| time_format                          | %H:%i:%s                                                                                                   |
| time_zone                            | +8:00                                                                                                      |
| tls_version                          |                                                                                                            |
| tmpdir                               |                                                                                                            |
| tmp_table_size                       | 16777216                                                                                                   |
| tracefile_identifier                 |                                                                                                            |
| transaction_isolation                | READ-COMMITTED                                                                                             |
| transaction_read_only                | OFF                                                                                                        |
| tx_isolation                         | READ-COMMITTED                                                                                             |
| tx_read_only                         | OFF                                                                                                        |
| undo_retention                       | 0                                                                                                          |
| unique_checks                        | ON                                                                                                         |
| validate_password_check_user_name    | on                                                                                                         |
| validate_password_length             | 0                                                                                                          |
| validate_password_mixed_case_count   | 0                                                                                                          |
| validate_password_number_count       | 0                                                                                                          |
| validate_password_policy             | low                                                                                                        |
| validate_password_special_char_count | 0                                                                                                          |
| version                              | 3.1.4-OceanBase CE                                                                                         |
| version_comment                      | OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14) |
| version_compile_machine              |                                                                                                            |
| version_compile_os                   |                                                                                                            |
| wait_timeout                         | 28800                                                                                                      |
| warning_count                        | 0                                                                                                          |
+--------------------------------------+------------------------------------------------------------------------------------------------------------+
156 rows in set (0.002 sec)

obclient [oceanbase]>

维护操作

#删除
docker rm obstandalone
# 启动
docker run -itd --memory 8G --name obstandalone oceanbase/oceanbase-ce
#查看
docker ps -a
#查看日志
docker logs obstandalone 

# oceanbase-standalone 镜像包含 obclient(OceanBase 数据库客户端)和默认连接脚本ob-mysql
# Connect to sys tenant
docker exec -it obstandalone ob-mysql sys 
# Connect to the root account of a general tenant
docker exec -it obstandalone ob-mysql root 
# Connect to the test account of a general tenant
docker exec -it obstandalone ob-mysql test 

# 进入容器
docker exec it obstandalone bash


问题

强制关机后导致,开机后启动docker

[root@localhost ~]# docker ps -a
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
# 启动
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                    COMMAND              CREATED             STATUS                        PORTS                    NAMES
77e89271893e        oceanbase/oceanbase-ce   "/bin/sh -c _boot"   37 hours ago        Exited (255) 10 seconds ago   0.0.0.0:2881->2881/tcp   obstandalone
[root@localhost ~]#
# 启动数据库
[root@localhost ~]# docker start obstandalone
obstandalone
[root@localhost ~]#
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                    COMMAND              CREATED             STATUS              PORTS                    NAMES
77e89271893e        oceanbase/oceanbase-ce   "/bin/sh -c _boot"   37 hours ago        Up 3 seconds        0.0.0.0:2881->2881/tcp   obstandalone
[root@localhost ~]#

猜你喜欢

转载自blog.csdn.net/u010895512/article/details/125920927