This topic describes how to deploy OceanBase Database Community Edition. This solution is suitable for deploying a single-node OceanBase Database instance. The deployed instance provides basic database functionality and helps you understand OceanBase Database. However, it does not support distributed capabilities or high availability. We recommend that you use this solution only for short-term testing.
Notice
This topic helps you quickly get started with OceanBase Database. For more information about how to experience the AP performance, see Recommended parameter configurations for AP scenarios.
Step 1: Set up the environment
Download and install the all-in-one package.
Download the all-in-one package of OceanBase Database Community Edition from OceanBase Download Center and upload it to a directory on your server.
In the directory where the installation package is located, run the following command 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 deploy OceanBase Database.
[admin@test001 ~]$ obd demoBy default, the
obd democommand deploys and starts OceanBase Database and its components (ODP, OBAgent, Grafana, and Prometheus) in the minimum configuration in the home directory of the current user, and the deployment name is fixed todemo.Note
When you install Grafana or Prometheus, the IP address of the public network or the IP address of the private network is output. In Alibaba Cloud or other cloud environments, the IP address of the private network may be output because the public IP address cannot be obtained. You must use the correct IP address.
Run the connection command in the output to connect to the database.
After the
obd democommand is executed, the command to connect to OceanBase Database by using OBClient is output. Here is an example:Connect to the database directly 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 by using the
obd democommand, you can configure a password for the demo cluster as follows:Modify the configuration file.
obd cluster edit-config demoAfter you run the preceding command to open the configuration file, add
root_password: xxxxunder the oceanbase-ce (Community Edition) or oceanbase (Enterprise Edition) component in the configuration file. Then, save and exit. Here is an example:oceanbase-ce: servers: - 127.0.0.1 global: home_path: /home/admin/oceanbase-ce ... # Omitted for brevity log_disk_size: 13G root_password: ******Restart the cluster.
After you modify and save the configuration file, obd outputs the command to restart the cluster. You can directly copy and execute the command. 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-00163e01cd7aFrom the output, you can see that after you modify the password of the
root@sysuser, you must execute theobd cluster reload democommand to restart the demo cluster.
Step 2: Create a table
Create a database.
Run the CREATE DATABASE statement to create a database.
Example: Create a database named quickstart, specify the character set as utf8mb4, and create a read/write attribute.
obclient> CREATE DATABASE quickstart DEFAULT CHARACTER SET utf8mb4 READ WRITE; Query OK, 1 row affectedCreate a table.
Run the
CREATE TABLEstatement to create a new table in the database.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
In this example, the earthquake_dataset.csv dataset from Kaggle is used.
Download the earthquake_dataset.csv file from Kaggle.
Copy the earthquake_dataset.csv file to the server where the OBServer node is located.
scp earthquake_dataset.csv admin@10.10.10.1:/home/admin/test_dataLog in to the server where the OBServer node is located.
Here is an example:
ssh admin@10.10.10.1Set the path of the imported file.
Notice
For security reasons, when you set the `secure_file_priv` system variable, you can only modify the global variable by executing an SQL statement through a local Unix Socket connection. For more information, see secure_file_priv.
Here is an example:
Log in to the server where the OBServer node is located.
ssh admin@10.10.10.1Execute the following command to connect to the
mysql001tenant through a local Unix Socket connection.Here is an example:
obclient -S /home/admin/oceanbase/run/sql.sock -uroot@mysql001 -p******Set the file directory 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****** -AImport data by using the
LOAD DATAstatement.Here is an example:
Use the following
LOAD DATAstatement to load data from the file to the database table. In this example:- The path and filename of the file to be loaded are specified as
/home/admin/test_data/earthquake_dataset.csv. - The name of the target table to be loaded is specified as
test. - The field separator in the data file is specified as a comma.
- The character-type fields in the data file are specified to be enclosed in double quotation marks.
- The line terminator in the data file is specified as a line break.
- The mapping between the columns in the data file and the columns in the target table is specified. The first column in the data file is mapped to the
placecolumn in the target 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);- The path and filename of the file to be loaded are specified as
Step 4: Query and analyze data
Log in to the server where the OBServer node is located.
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 data for 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