From 4606b76dab1ab28b6bfbad3c4d4853367666e026 Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 16:53:03 +0800 Subject: [PATCH 01/15] Create example.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ruby代码示例 --- ruby/example.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ruby/example.rb diff --git a/ruby/example.rb b/ruby/example.rb new file mode 100644 index 0000000..8678787 --- /dev/null +++ b/ruby/example.rb @@ -0,0 +1,41 @@ +require 'mysql2' + +def connect_to_oceanbase(host, port, username, password, database) + begin + # 创建数据库连接 + client = Mysql2::Client.new( + host: host, + port: port, + username: username, + password: password, + database: database + ) + + puts "连接到OceanBase数据库成功" + + # 执行一个简单的查询 + results = client.query("SELECT DATABASE();") + + results.each do |row| + puts "连接到的数据库: #{row['DATABASE()']}" + end + + # 你可以在这里执行其他的SQL查询或操作 + + client.close + puts "MySQL连接已关闭" + + rescue Mysql2::Error => e + puts "连接到OceanBase数据库失败: #{e.error}" + end +end + +if __FILE__ == $0 + connect_to_oceanbase( + '172.30.3.244', + 2881, + 'root', + 'password', + 'test' + ) +end From 4f9480adeb4e293357fd5f48062a6983fadd1843 Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 16:58:11 +0800 Subject: [PATCH 02/15] Create README-CN.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 中文README --- ruby/README-CN.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ruby/README-CN.md diff --git a/ruby/README-CN.md b/ruby/README-CN.md new file mode 100644 index 0000000..ea98044 --- /dev/null +++ b/ruby/README-CN.md @@ -0,0 +1,64 @@ +# Ruby连接 OceanBase 指南(mysql2) + +[English](README.md) | 简体中文 + +本文介绍如何通过 mysql2驱动连接 OceanBase 数据库。 + +## 快速开始 + +为了防止环境问题,推荐使用 anaconda 配置 python 3.x 环境。 + +在开始之前,需要先确保 mysql2已安装。 + +以 [example.rb](example.rb) 为例。 + +```python +require 'mysql2' + +def connect_to_oceanbase(host, port, username, password, database) + begin + # 创建数据库连接 + client = Mysql2::Client.new( + host: host, + port: port, + username: username, + password: password, + database: database + ) + + puts "连接到OceanBase数据库成功" + + # 执行一个简单的查询 + results = client.query("SELECT DATABASE();") + + results.each do |row| + puts "连接到的数据库: #{row['DATABASE()']}" + end + + # 你可以在这里执行其他的SQL查询或操作 + + client.close + puts "MySQL连接已关闭" + + rescue Mysql2::Error => e + puts "连接到OceanBase数据库失败: #{e.error}" + end +end + +if __FILE__ == $0 + connect_to_oceanbase( + '127.0.0.1', + 2881, + 'root', + 'password', + 'test' + ) +end + +``` + +修改代码中的连接信息,之后你就可以直接使用命令行运行示例代码。 + +```bash +ruby [example.rb](example.rb) +``` From 91bc0a6237ca8bd7d12c5bb03e163cbb8cecabeb Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 16:59:02 +0800 Subject: [PATCH 03/15] Delete ruby/README-CN.md --- ruby/README-CN.md | 64 ----------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 ruby/README-CN.md diff --git a/ruby/README-CN.md b/ruby/README-CN.md deleted file mode 100644 index ea98044..0000000 --- a/ruby/README-CN.md +++ /dev/null @@ -1,64 +0,0 @@ -# Ruby连接 OceanBase 指南(mysql2) - -[English](README.md) | 简体中文 - -本文介绍如何通过 mysql2驱动连接 OceanBase 数据库。 - -## 快速开始 - -为了防止环境问题,推荐使用 anaconda 配置 python 3.x 环境。 - -在开始之前,需要先确保 mysql2已安装。 - -以 [example.rb](example.rb) 为例。 - -```python -require 'mysql2' - -def connect_to_oceanbase(host, port, username, password, database) - begin - # 创建数据库连接 - client = Mysql2::Client.new( - host: host, - port: port, - username: username, - password: password, - database: database - ) - - puts "连接到OceanBase数据库成功" - - # 执行一个简单的查询 - results = client.query("SELECT DATABASE();") - - results.each do |row| - puts "连接到的数据库: #{row['DATABASE()']}" - end - - # 你可以在这里执行其他的SQL查询或操作 - - client.close - puts "MySQL连接已关闭" - - rescue Mysql2::Error => e - puts "连接到OceanBase数据库失败: #{e.error}" - end -end - -if __FILE__ == $0 - connect_to_oceanbase( - '127.0.0.1', - 2881, - 'root', - 'password', - 'test' - ) -end - -``` - -修改代码中的连接信息,之后你就可以直接使用命令行运行示例代码。 - -```bash -ruby [example.rb](example.rb) -``` From d57349980036d423d07dd2b775cb8c5418800b34 Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:03:05 +0800 Subject: [PATCH 04/15] Create README-CN.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加中文README --- ruby/mysql2/README-CN.md | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ruby/mysql2/README-CN.md diff --git a/ruby/mysql2/README-CN.md b/ruby/mysql2/README-CN.md new file mode 100644 index 0000000..a448b85 --- /dev/null +++ b/ruby/mysql2/README-CN.md @@ -0,0 +1,68 @@ +# Ruby连接 OceanBase 指南(mysql2) + +[English](README.md) | 简体中文 + +本文介绍如何通过 mysql2驱动连接 OceanBase 数据库。 + +## 快速开始 + +在开始之前,需要先确保 mysql2已安装。 + +安装命令 + +``` +gem install mysql2 +``` + +以 [example.rb](example.rb) 为例。 + +```python +require 'mysql2' + +def connect_to_oceanbase(host, port, username, password, database) + begin + # 创建数据库连接 + client = Mysql2::Client.new( + host: host, + port: port, + username: username, + password: password, + database: database + ) + + puts "连接到OceanBase数据库成功" + + # 执行一个简单的查询 + results = client.query("SELECT DATABASE();") + + results.each do |row| + puts "连接到的数据库: #{row['DATABASE()']}" + end + + # 你可以在这里执行其他的SQL查询或操作 + + client.close + puts "MySQL连接已关闭" + + rescue Mysql2::Error => e + puts "连接到OceanBase数据库失败: #{e.error}" + end +end + +if __FILE__ == $0 + connect_to_oceanbase( + '127.0.0.1', + 2881, + 'root', + 'password', + 'test' + ) +end + +``` + +修改代码中的连接信息,之后你就可以直接使用命令行运行示例代码。 + +```bash +ruby example.rb +``` From ff9270767ab759fdef8f1a7a4a41261b89ca49ae Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:04:12 +0800 Subject: [PATCH 05/15] Create example.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 示例文件 --- ruby/mysql2/example.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ruby/mysql2/example.rb diff --git a/ruby/mysql2/example.rb b/ruby/mysql2/example.rb new file mode 100644 index 0000000..8678787 --- /dev/null +++ b/ruby/mysql2/example.rb @@ -0,0 +1,41 @@ +require 'mysql2' + +def connect_to_oceanbase(host, port, username, password, database) + begin + # 创建数据库连接 + client = Mysql2::Client.new( + host: host, + port: port, + username: username, + password: password, + database: database + ) + + puts "连接到OceanBase数据库成功" + + # 执行一个简单的查询 + results = client.query("SELECT DATABASE();") + + results.each do |row| + puts "连接到的数据库: #{row['DATABASE()']}" + end + + # 你可以在这里执行其他的SQL查询或操作 + + client.close + puts "MySQL连接已关闭" + + rescue Mysql2::Error => e + puts "连接到OceanBase数据库失败: #{e.error}" + end +end + +if __FILE__ == $0 + connect_to_oceanbase( + '172.30.3.244', + 2881, + 'root', + 'password', + 'test' + ) +end From 40f117e0a42ddb42722f727834804ed74ae2d4df Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:08:35 +0800 Subject: [PATCH 06/15] Delete ruby/example.rb --- ruby/example.rb | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 ruby/example.rb diff --git a/ruby/example.rb b/ruby/example.rb deleted file mode 100644 index 8678787..0000000 --- a/ruby/example.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'mysql2' - -def connect_to_oceanbase(host, port, username, password, database) - begin - # 创建数据库连接 - client = Mysql2::Client.new( - host: host, - port: port, - username: username, - password: password, - database: database - ) - - puts "连接到OceanBase数据库成功" - - # 执行一个简单的查询 - results = client.query("SELECT DATABASE();") - - results.each do |row| - puts "连接到的数据库: #{row['DATABASE()']}" - end - - # 你可以在这里执行其他的SQL查询或操作 - - client.close - puts "MySQL连接已关闭" - - rescue Mysql2::Error => e - puts "连接到OceanBase数据库失败: #{e.error}" - end -end - -if __FILE__ == $0 - connect_to_oceanbase( - '172.30.3.244', - 2881, - 'root', - 'password', - 'test' - ) -end From 776d0bce7cf66a1c2053b10d59cddff5133383fc Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:09:09 +0800 Subject: [PATCH 07/15] Create README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 英文README --- ruby/mysql2/README | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ruby/mysql2/README diff --git a/ruby/mysql2/README b/ruby/mysql2/README new file mode 100644 index 0000000..baa480d --- /dev/null +++ b/ruby/mysql2/README @@ -0,0 +1,68 @@ +# Ruby Connection OceanBase Guide (Mysql2) + +[English](README.md) | 简体中文 + +This article introduces how to connect to OceanBase database through mysql2 driver. + +## Quick Start + +Before starting, it is necessary to ensure that mysql2 is installed. + +Installation command + +``` +gem install mysql2 +``` + +Taking [example.rb](example.rb) as an example. + +```python +require 'mysql2' + +def connect_to_oceanbase(host, port, username, password, database) + begin + # 创建数据库连接 + client = Mysql2::Client.new( + host: host, + port: port, + username: username, + password: password, + database: database + ) + + puts "连接到OceanBase数据库成功" + + # 执行一个简单的查询 + results = client.query("SELECT DATABASE();") + + results.each do |row| + puts "连接到的数据库: #{row['DATABASE()']}" + end + + # 你可以在这里执行其他的SQL查询或操作 + + client.close + puts "MySQL连接已关闭" + + rescue Mysql2::Error => e + puts "连接到OceanBase数据库失败: #{e.error}" + end +end + +if __FILE__ == $0 + connect_to_oceanbase( + '127.0.0.1', + 2881, + 'root', + 'password', + 'test' + ) +end + +``` + +Modify the connection information in the code, and then you can directly run the example code using the command line. + +```bash +ruby example.rb +``` From 029a03729882309119f7270adc108fbb41914b87 Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:09:31 +0800 Subject: [PATCH 08/15] Rename README to README.md --- ruby/mysql2/{README => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ruby/mysql2/{README => README.md} (100%) diff --git a/ruby/mysql2/README b/ruby/mysql2/README.md similarity index 100% rename from ruby/mysql2/README rename to ruby/mysql2/README.md From 9fcb7cebae2d62b4bb4c82e33d6a5f8d746c128f Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:10:33 +0800 Subject: [PATCH 09/15] Update README.md --- ruby/mysql2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/mysql2/README.md b/ruby/mysql2/README.md index baa480d..8c856b3 100644 --- a/ruby/mysql2/README.md +++ b/ruby/mysql2/README.md @@ -1,6 +1,6 @@ # Ruby Connection OceanBase Guide (Mysql2) -[English](README.md) | 简体中文 +English | [简体中文](example.rb) This article introduces how to connect to OceanBase database through mysql2 driver. From 1c261d541dc5978b35a470c829ceb8658cf5076b Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 17:11:02 +0800 Subject: [PATCH 10/15] Update README.md --- ruby/mysql2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/mysql2/README.md b/ruby/mysql2/README.md index 8c856b3..55f7e9a 100644 --- a/ruby/mysql2/README.md +++ b/ruby/mysql2/README.md @@ -1,6 +1,6 @@ # Ruby Connection OceanBase Guide (Mysql2) -English | [简体中文](example.rb) +English | [简体中文](README-CN.md) This article introduces how to connect to OceanBase database through mysql2 driver. From e795765533cda279d667e5dda2ba9009dacd35f5 Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 20:55:59 +0800 Subject: [PATCH 11/15] Update ci.yml add ruby --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e9b74e..fb80f71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,9 @@ jobs: - name: 'springboot' language: 'java' with_oceanbase_container: true + - name: 'mysql2' + language: 'ruby' + with_oceanbase_container: true uses: ./.github/workflows/basic-workflow.yml with: module: ${{ matrix.module.name }} From 1460ea492553067f566d33b588b452a73d33e9ca Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 21:04:38 +0800 Subject: [PATCH 12/15] Create run.sh add run.sh --- ruby/mysql2/run.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ruby/mysql2/run.sh diff --git a/ruby/mysql2/run.sh b/ruby/mysql2/run.sh new file mode 100644 index 0000000..e17174b --- /dev/null +++ b/ruby/mysql2/run.sh @@ -0,0 +1,2 @@ +gem install mysql2 +ruby example.rb From 786a2ad78c2b8820079d57152618681402dde951 Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 21:20:00 +0800 Subject: [PATCH 13/15] Create README.md add README.md --- ruby/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ruby/README.md diff --git a/ruby/README.md b/ruby/README.md new file mode 100644 index 0000000..8092b89 --- /dev/null +++ b/ruby/README.md @@ -0,0 +1,3 @@ +## Introduction + +Please add RUBY samples in this directory. From a47b7c48d6558174ca606435bfd7d9a468bd631d Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 21:29:22 +0800 Subject: [PATCH 14/15] Update example.rb modify host --- ruby/mysql2/example.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/mysql2/example.rb b/ruby/mysql2/example.rb index 8678787..8aeda6a 100644 --- a/ruby/mysql2/example.rb +++ b/ruby/mysql2/example.rb @@ -32,10 +32,10 @@ def connect_to_oceanbase(host, port, username, password, database) if __FILE__ == $0 connect_to_oceanbase( - '172.30.3.244', + '127.0.0.1', 2881, 'root', - 'password', + '', 'test' ) end From 4924412f19762a6de5481dac0c6b6d4a5fa68dbc Mon Sep 17 00:00:00 2001 From: zhs722 <90595458+zhs722@users.noreply.github.com> Date: Thu, 30 May 2024 21:45:53 +0800 Subject: [PATCH 15/15] Create example.rb add sequel --- ruby/sequel/example.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ruby/sequel/example.rb diff --git a/ruby/sequel/example.rb b/ruby/sequel/example.rb new file mode 100644 index 0000000..df16ae3 --- /dev/null +++ b/ruby/sequel/example.rb @@ -0,0 +1,17 @@ +require 'sequel' + +# 连接到OceanBase数据库 +DB = Sequel.connect( + adapter: 'mysql2', + host: '127.0.0.1', + port: 2881, + user: 'root', + password: '', + database: 'test' +) + +if DB.test_connection + puts "成功连接到OceanBase数据库" +else + puts "连接到OceanBase数据库失败" +end