This topic uses the deployment of OceanBase Database Community Edition as an example. It is intended for scenarios where only a single machine is available, enabling you to quickly set up a functional OceanBase Database environment. The deployed environment provides basic database functionality and serves as an effective way to familiarize yourself with OceanBase Database; however, it lacks distributed capabilities and high availability features, so it is not recommended for long-term use.
Notice
This topic aims to help you get started with OceanBase Database. If you want to further experience analytical processing (AP) performance, we recommend that you use the recommended parameter configurations. For more information, see Recommended parameter configurations for AP scenarios.
Step 1: Quickly set up the experience environment
Download and install the all-in-one package.
Download the all-in-one package for the Community Edition from OceanBase Download Center and upload it to any directory on your server.
In the directory where the package is located, run the following commands to decompress and install the package.
[admin@test001 ~]$ tar -xzf oceanbase-all-in-one-*.tar.gz [admin@test001 ~]$ cd oceanbase-all-in-one/bin/ [admin@test001 bin]$ ./install.sh [admin@test001 bin]$ source ~/.oceanbase-all-in-one/bin/env.shRun the following command to quickly deploy OceanBase Database.
[admin@test001 ~]$ obd demoBy default, the
obd democommand deploys OceanBase Database and its components (ODP, OBAgent, Grafana, and Prometheus) with minimum specifications, and then starts them in the home directory of the current user. The name of the deployed cluster is fixed todemo.Note
If you install Grafana or Prometheus, its access address is returned in the command output. On Alibaba Cloud or other cloud environments, it is possible that an intranet IP address is returned due to the inability to obtain a public IP address. You must use the correct public IP address.
Run the connection command in the output to connect to the database.
After the
obd democommand succeeds, you will find the command to connect to OceanBase Database through OBClient. Here are some examples:Directly connect to the database through port 2881
[admin@test001 ~]$ obclient -h127.0.0.1 -P2881 -uroot@sys -Doceanbase -AConnect to the database through ODP
[admin@test001 ~]$ obclient -h127.0.0.1 -P2883 -uroot@sys -Doceanbase -A
(Optional) Configure the password.
After you deploy OceanBase Database in the
democluster by using theobd democommand, you can follow the steps below to configure a password for thedemocluster.Modify the configuration file.
obd cluster edit-config demoAfter you run the above command to open the configuration file, add
root_password: xxxxunder the oceanbase-ce or oceanbase component, based on the edition, in the configuration file. Then save the file and exit. Here is an example:oceanbase-ce: servers: - 127.0.0.1 global: home_path: /home/admin/oceanbase-ce ... # Some parameters are omitted here. log_disk_size: 13G root_password: ******Restart the cluster.
After you modify and save the configuration file, obd will output the restart command. You can directly copy and run it. Here is an example.
[admin@test001 ~]$ obd cluster edit-config demo Search param plugin and load ok Search param plugin and load ok Parameter check ok Save deploy "demo" configuration Use `obd cluster reload demo` to make changes take effect. Trace ID: 29dd12fa-3d73-11ee-91bc-00163e01cd7a If you want to view detailed obd logs, please run: obd display-trace 29dd12fa-3d73-11ee-91bc-00163e01cd7aAs shown in the output, after you modify the password of the
root@sysuser in the configuration file, you must runobd cluster reload demoto restart the demo cluster.
Step 2: Create a table
Create a database.
You can run the CREATE DATABASE statement to create a database.
Here is an example: create a database named quickstart, set its character set to utf8mb4, and set its read and write properties.
obclient> CREATE DATABASE quickstart DEFAULT CHARACTER SET utf8mb4 READ WRITE; Query OK, 1 row affectedCreate a table.
You can run the
CREATE TABLEstatement to create a table in the database.Here is an example: create a table named
testin thequickstartdatabase.obclient> USE quickstart; Database changed obclient> CREATE TABLE test (place VARCHAR(500), latitude VARCHAR(50),longitude VARCHAR(50), country VARCHAR(1000), continent VARCHAR(100), magnitude DECIMAL(3, 1)); Query OK, 0 rows affected
Step 3: Import data
The sample dataset used in this topic is the earthquake_dataset.csv file from Kaggle.
Download the earthquake_dataset.csv file from Kaggle.
Copy the earthquake_dataset.csv file to the server where the OBServer node resides.
scp earthquake_dataset.csv admin@10.10.10.1:/home/admin/test_dataLog in to the server where the OBServer node to connect to resides.
Here is an example:
ssh admin@10.10.10.1Set the file path for importing data.
Notice
For security reasons, when you set the system variable `secure_file_priv`, you can connect to the database only through a local socket to execute the SQL statement that modifies the global variable. For more information, see secure_file_priv.
Here is an example:
Log in to the server where the OBServer node to connect to resides.
ssh admin@10.10.10.1Connect to the
mysql001tenant through a local Unix socket.Here is an example:
obclient -S /home/admin/oceanbase/run/sql.sock -uroot@mysql001 -p******Set the file path to
/, which indicates that any path can be accessed.SET GLOBAL SECURE_FILE_PRIV = "/";
Reconnect to the database.
Here is an example:
obclient -h127.0.0.1 -P2881 -utest_user001@mysql001 -p****** -AUse the
LOAD DATAstatement to import data.Here is an example:
Execute the following
LOAD DATAstatement to load data from the specified file to a database table. In this statement:- Set the path and file name of the file to be loaded to
/home/admin/test_data/earthquake_dataset.csv. - Set the name of the destination table to which the data is to be loaded to
test. - Specify comma (,) as the separator of fields in the data file.
- Specify that fields (of the character type) in the data file be enclosed in double quotation marks (").
- Specify that line breaks be used as the end characters of lines in the data file.
- Specify the mappings between columns in the source file and those in the destination table. The first column in the source file will be mapped to the
placecolumn in the destination table, the second column to thelatitudecolumn, the third column to thelongitudecolumn, and so on.
obclient [test]> LOAD DATA LOCAL INFILE '/home/admin/test_data/earthquake_dataset.csv' INTO TABLE test FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (place,latitude,longitude,country,continent,magnitude);- Set the path and file name of the file to be loaded to
Step 4: Perform query analysis
Log in to the server where the OBServer node to connect to resides.
ssh admin@10.10.10.1Connect to the database.
Here is an example:
obclient -h127.0.0.1 -P2881 -utest_user001@mysql001 -p****** -AQuery the number of earthquakes in a specific
place.obclient [quickstart]> select * from test where place = 'Santiago'; +----------+----------+-----------+---------+----------------+-----------+ | place | latitude | longitude | country | continent | magnitude | +----------+----------+-----------+---------+----------------+-----------+ | Santiago | -33.4463 | -70.6682 | Chile | South America | 4.8 | | Santiago | -33.4521 | -70.6647 | Chile | South America | 4.5 | | Santiago | -33.4505 | -70.6717 | Chile | South America | 5.2 | | Santiago | -33.4489 | -70.6693 | Chile | South America | 5.6 | | Santiago | -33.4472 | -70.6659 | Chile | South America | 4.1 | +----------+----------+-----------+---------+----------------+-----------+ 5 rows in setCount the number of earthquakes in each continent.
obclient [quickstart]> select continent,count(*) from test group by continent; +----------------+----------+ | continent | count(*) | +----------------+----------+ | South America | 90 | | Africa | 580 | | Antarctica | 70 | | North America | 190 | | Oceania | 45 | | Asia | 155 | | Europe | 135 | +----------------+----------+ 7 rows in set