OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Cloud

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Cloud
    iconOceanBase Cloud
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET

      Connect to OceanBase Cloud by using Sequel

      Last Updated:2026-06-01 08:35:36  Updated
      Share
      What is on this page
      Prerequisites
      Procedure
      Step 1: Check the versions of Ruby and RubyGems
      Step 2: Install the required gem
      Step 3: Obtain the connection information of OceanBase Cloud
      Step 4: Create a sample program
      Step 5: Run the sample program
      Common issues
      Performance optimization suggestions

      folded

      Share

      This topic describes how to use Sequel to connect to OceanBase Cloud and perform basic operations such as creating tables, inserting data, and querying data.

      Prerequisites

      • You have installed Ruby and RubyGems.
      • You have registered an OceanBase Cloud account and created an instance and a MySQL compatible tenant. For more information, see Create an instance and Create a tenant.

      Procedure

      1. Check the versions of Ruby and RubyGems.
      2. Install the required gem.
      3. Obtain the connection information of OceanBase Cloud.
      4. Create a sample program.
      5. Run the sample program.

      Step 1: Check the versions of Ruby and RubyGems

      Run the following command in the terminal to check the versions of Ruby and RubyGems:

      ruby -v
      gem -v
      

      Step 2: Install the required gem

      Run the following command to install Sequel and mysql2:

      gem install sequel mysql2
      

      Step 3: Obtain the connection information of OceanBase Cloud

      1. Log in to the OceanBase Cloud console. In the instance list, expand the information of the target instance, and select Connect > Get Connection String under the target tenant.

        For more information, see Obtain the connection string.

      2. Fill in the corresponding information in the URL below based on the created OceanBase Cloud database.

        mysql -h$host -P$port -u$user_name -p$password -D$database_name
        

        Parameter description:

        • $host: the endpoint of the OceanBase Cloud database, for example, t********.********.oceanbase.cloud.
        • $port: the port of the OceanBase Cloud database. The default value is 3306.
        • $database_name: the name of the database to be accessed.
        • $user_name: the account for accessing the database.
        • $password: the password of the account.

      Step 4: Create a sample program

      1. Create a configuration file named config.rb:

        PASSWORD = ENV['OB_PASSWORD'] || 'your_password'
        
        CLIENT_CONFIG = {
          adapter: 'mysql2',
          host: 'your_host',
          port: your_port,
          username: 'your_username',
          password: PASSWORD,
          all_databases: true
        }
        
      2. Create a sample program named main.rb:

        require 'sequel'
        require 'sequel/adapters/mysql2'
        require File.expand_path('config.rb', __dir__)
        
        # Create a connection
        db = Sequel.connect(CLIENT_CONFIG)
        
        # Create a database
        db_name = "ruby_test_db"
        db.run("CREATE DATABASE IF NOT EXISTS #{db_name}")
        
        db.disconnect
        
        # Reconnect to the new database
        CLIENT_CONFIG[:database] = db_name
        db = Sequel.connect(CLIENT_CONFIG)
        puts "Database '#{db_name}' selected"
        
        # Create a table
        db.run("DROP TABLE IF EXISTS users")
        db.run("CREATE TABLE users (
          id INT AUTO_INCREMENT PRIMARY KEY,
          name VARCHAR(255) NOT NULL,
          created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        )")
        
        # Insert sample data
        sample_names = ["Alice", "Bob", "Charlie", "David"]
        sample_names.each do |name|
          db.run("INSERT INTO users (name) VALUES ('#{name}')")
        end
        
        puts "Table created and sample data inserted successfully"
        puts "Inserted #{sample_names.size} sample records"
        
        # Query and display all data
        results = db[:users]
        puts "\nUsers:"
        results.each do |row|
          puts "ID: #{row[:id]}, Name: #{row[:name]}, Created at: #{row[:created_at]}"
        end
        
        # Close the connection
        db.disconnect
        

      Step 5: Run the sample program

      1. Run the program:

        ruby main.rb
        

        Expected output:

        Database 'ruby_test_db' selected
        Table created and sample data inserted successfully
        Inserted 4 sample records
        
        Users:
        ID: 1, Name: Alice, Created at: 2025-05-21 15:20:06 +0800
        ID: 2, Name: Bob, Created at: 2025-05-21 15:20:06 +0800
        ID: 3, Name: Charlie, Created at: 2025-05-21 15:20:06 +0800
        ID: 4, Name: David, Created at: 2025-05-21 15:20:06 +0800
        

      Common issues

      1. Connection error: If you cannot connect to the database, check the following:

        • Whether the database endpoint and port are correct
        • Whether the username and password are correct
        • Whether the network connection is normal
      2. Permission error: If you encounter a permission-related error, make sure the user has sufficient permissions to perform the required operations.

      3. SQL syntax error: If there is a syntax error in the SQL statement, check whether the SQL statement is correctly written.

      Performance optimization suggestions

      1. Use Sequel's batch operations.
      2. Use a connection pool to manage database connections.
      3. Use precompiled queries.
      4. Use caching appropriately.
      5. Optimize database indexes.

      Previous topic

      Connect to OceanBase Cloud by using mysql2
      Last

      Next topic

      Database connection pool configuration
      Next
      What is on this page
      Prerequisites
      Procedure
      Step 1: Check the versions of Ruby and RubyGems
      Step 2: Install the required gem
      Step 3: Obtain the connection information of OceanBase Cloud
      Step 4: Create a sample program
      Step 5: Run the sample program
      Common issues
      Performance optimization suggestions