OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Database

  • Overview of the ecosystem
  • ORM frameworks
    • Java
      • Spring Boot
      • Spring Batch
      • Use Spring JDBC to connect to OceanBase Database
      • Spring Data JPA
      • Hibernate
      • MyBatis
      • jOOQ
    • Python
      • Use SQLAlchemy to connect to OceanBase Database
      • Connect to OceanBase Database by using peewee
      • Use Tortoise ORM to connect to OceanBase Database
    • Go
      • Connect to OceanBase Database by using GORM
      • beego ORM
    • Rust
      • SeaORM Connection to OceanBase Database
      • Diesel Connection to OceanBase Database
    • Ruby
      • Active Record
      • Sequel Connection to OceanBase Database
      • Connect to OceanBase Database by using Ruby on Rails
    • Node.js
      • Sequelize
      • TypeORM
      • Prisma
      • Drizzle
    • C#
      • Dapper
      • SqlSugar
      • FreeSQL
    • PHP
      • Connect to OceanBase Database by using the Yii 2.0 ORM
      • Connect to OceanBase Database by using Laravel Eloquent ORM
      • CakePHP
  • Database version management
    • Liquibase
    • Flyway
  • Data integration
    • Flink
      • Apache Flink
      • Flink DirectLoad
      • Flink Connector OceanBase
    • dbt
    • SeaTunnel
    • Maxwell
    • Debezium
    • Spark Catalog
    • NiFi
    • Qlik Replicate
    • RisingWave CDC
    • Flume
    • Migrate data from SQL Server to OceanBase Database by using MySQL Workbench
  • SQL development
    • WebLogic
    • DBeaver
    • Navicat
    • DataGrip
    • TablePlus
    • DMS
  • Orchestration and scheduling
    • Airflow
    • PowerJob
    • DolphinScheduler
    • Linkis
  • Visualization tools
    • Superset
    • Excel
    • Power BI
    • Quick BI
    • Tableau
    • GuanData
    • vividime
    • DataV
    • Metabase
    • Redash
    • FineReport
  • Database management
    • NineData
    • Bytebase
    • DataHub
    • Zabbix
  • AI
    • OpenAI
    • Qwen
    • LangChain
    • LlamaIndex
    • Dify
    • n8n
    • Trae
    • SpringAI
    • Cline
    • Cursor
    • Continue
    • MCP Toolbox
    • CamelAI
    • Firecrawl
    • Hugging Face
    • Ollama
    • Google Gemini
    • Cloudflare Workers AI
    • DB GPT
    • Jina AI
    • Augment Code
    • Claude Code
    • Kiro
    • GPT4All
  • Application
    • Ghost
    • Jira
    • Seata
    • SAP Crystal Reports
  • Middleware
    • Apache Pulsar

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Database
  3. master

Sequel connection to OceanBase Database

Last Updated:2026-09-04 07:40:45

Prerequisites
Procedure
Step 1: Check the versions of Ruby and RubyGems
Step 2: Install the required gems
Step 3: Obtain the connection information of OceanBase Database
Step 4: Create a sample program
Step 5: Run the sample program
FAQ
Performance optimization

Applicability

Sequel is applicable to OceanBase Database in MySQL mode.

This topic describes how to use Sequel and OceanBase Database to build an application that can perform basic operations such as creating tables, inserting data, and querying data.

Prerequisites

  • You have installed Ruby and RubyGems.
  • You have installed OceanBase Database and created a tenant in MySQL mode.

Procedure

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

Step 1: Check the versions of Ruby and RubyGems

Open the terminal and run the following command to check the versions of Ruby and RubyGems:

ruby -v
gem -v

Step 2: Install the required gems

Run the following command to install Sequel and mysql2:

gem install sequel mysql2

Step 3: Obtain the connection information of OceanBase Database

Contact the deployment engineer or administrator of OceanBase Database to obtain the connection string.

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

Parameter description:

  • $host: the IP address for connecting to OceanBase Database.
  • $port: the port for connecting to OceanBase Database.
  • $database_name: the name of the database to be accessed.
  • $user_name: the username of the tenant.
  • $password: the password of the tenant.

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 return result:

    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
    

FAQ

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

    • Whether the database address 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 that the user has sufficient permissions to perform the required operations.

  3. SQL syntax error: If the SQL statement has a syntax error, check the syntax of the SQL statement.

Performance optimization

  1. Use batch operations of Sequel.
  2. Use a connection pool to manage database connections.
  3. Use precompiled queries.
  4. Use cache reasonably.
  5. Optimize database indexes.

Previous topic

Active Record
Last

Next topic

Connect to OceanBase Database by using Ruby on Rails
Next
on this page
Prerequisites
Procedure
Step 1: Check the versions of Ruby and RubyGems
Step 2: Install the required gems
Step 3: Obtain the connection information of OceanBase Database
Step 4: Create a sample program
Step 5: Run the sample program
FAQ
Performance optimization