利用MySQL或obclient客户端毗连OceanBase数据库

饭宝  金牌会员 | 2025-1-14 19:38:40 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 889|帖子 889|积分 2667

==========================================
现供职于某上市互联网公司担当DBA
Oracle & PG ACE称号,
拥有 Oracle OCM、AWS、以及部分国产数据库等产品认证。
喜好技术分享,热爱交友,也热爱健身。
2019年加入墨天轮,目前已发表了一百多篇原创文章,曾多次获评"月度墨力之星"。
OceanBase、PG中国分会、IvorySQL等南京地域组织者,也是TeckTalk技术交流社区首创人。
个人微信公众号: 尚雷的驿站
可微信公众号搜索 : 尚雷的驿站
==========================================

一、MySQL毗连OceanBase

1.1、安装MySQL客户端

   注:本次选择在Centos7上安装最新的MySQL 8.0 客户端。
  1.1.1 安装Yum Repository

  1. [root@obproxy-node ~]# yum -y install http://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
  2. Loaded plugins: fastestmirror
  3. mysql80-community-release-el7-5.noarch.rpm                                                                                                                                                                                                              |  11 kB  00:00:00   
  4. Examining /var/tmp/yum-root-KrLMEB/mysql80-community-release-el7-5.noarch.rpm: mysql80-community-release-el7-5.noarch
  5. Marking /var/tmp/yum-root-KrLMEB/mysql80-community-release-el7-5.noarch.rpm to be installed
  6. Resolving Dependencies
  7. --> Running transaction check
  8. ---> Package mysql80-community-release.noarch 0:el7-5 will be installed
  9. --> Finished Dependency Resolution
  10. Dependencies Resolved
  11. ===============================================================================================================================================================================================================================================================================
  12. Package                                                                 Arch                                                 Version                                              Repository                                                                             Size
  13. ===============================================================================================================================================================================================================================================================================
  14. Installing:
  15. mysql80-community-release                                               noarch                                               el7-5                                                /mysql80-community-release-el7-5.noarch                                               9.1 k
  16. Transaction Summary
  17. ===============================================================================================================================================================================================================================================================================
  18. Install  1 Package
  19. Total size: 9.1 k
  20. Installed size: 9.1 k
  21. Downloading packages:
  22. Running transaction check
  23. Running transaction test
  24. Transaction test succeeded
  25. Running transaction
  26. Warning: RPMDB altered outside of yum.
  27.   Installing : mysql80-community-release-el7-5.noarch                                                                                                                                                                                                                      1/1
  28.   Verifying  : mysql80-community-release-el7-5.noarch                                                                                                                                                                                                                      1/1
  29. Installed:
  30.   mysql80-community-release.noarch 0:el7-5                                                                                                                                                                                                                                    
  31. Complete!
复制代码
1.1.2 安装MySQL客户端

  1. [root@obproxy-node bin]# yum -y install mysql
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package mysql-community-client.x86_64 0:8.0.31-1.el7 will be installed
  7. --> Processing Dependency: mysql-community-client-plugins = 8.0.31-1.el7 for package: mysql-community-client-8.0.31-1.el7.x86_64
  8. --> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.31-1.el7.x86_64
  9. --> Running transaction check
  10. ---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
  11. --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
  12. --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
  13. ---> Package mysql-community-client-plugins.x86_64 0:8.0.31-1.el7 will be installed
  14. ---> Package mysql-community-libs.x86_64 0:8.0.31-1.el7 will be obsoleting
  15. --> Processing Dependency: mysql-community-common(x86-64) >= 8.0.11 for package: mysql-community-libs-8.0.31-1.el7.x86_64
  16. --> Running transaction check
  17. ---> Package mysql-community-common.x86_64 0:8.0.31-1.el7 will be installed
  18. ---> Package mysql-community-libs-compat.x86_64 0:8.0.31-1.el7 will be obsoleting
  19. --> Finished Dependency Resolution
  20. Dependencies Resolved
  21. ===============================================================================================================================================================================================================================================================================
  22. Package                                                                        Arch                                                   Version                                                         Repository                                                         Size
  23. ===============================================================================================================================================================================================================================================================================
  24. Installing:
  25. mysql-community-client                                                         x86_64                                                 8.0.31-1.el7                                                    mysql80-community                                                  16 M
  26. mysql-community-libs                                                           x86_64                                                 8.0.31-1.el7                                                    mysql80-community                                                 1.5 M
  27.      replacing  mariadb-libs.x86_64 1:5.5.68-1.el7
  28. mysql-community-libs-compat                                                    x86_64                                                 8.0.31-1.el7                                                    mysql80-community                                                 670 k
  29.      replacing  mariadb-libs.x86_64 1:5.5.68-1.el7
  30. Installing for dependencies:
  31. mysql-community-client-plugins                                                 x86_64                                                 8.0.31-1.el7                                                    mysql80-community                                                 2.5 M
  32. mysql-community-common                                                         x86_64                                                 8.0.31-1.el7                                                    mysql80-community                                                 647 k
  33. Transaction Summary
  34. ===============================================================================================================================================================================================================================================================================
  35. Install  3 Packages (+2 Dependent packages)
  36. Total download size: 21 M
  37. Downloading packages:
  38. warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY                                                                   ] 749 kB/s | 3.6 MB  00:00:24 ETA
  39. Public key for mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm is not installed
  40. (1/5): mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm                                                                                                                                                                                           | 2.5 MB  00:00:03   
  41. (2/5): mysql-community-common-8.0.31-1.el7.x86_64.rpm                                                                                                                                                                                                   | 647 kB  00:00:00   
  42. (3/5): mysql-community-libs-8.0.31-1.el7.x86_64.rpm                                                                                                                                                                                                     | 1.5 MB  00:00:00   
  43. (4/5): mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm                                                                                                                                                                                              | 670 kB  00:00:00   
  44. (5/5): mysql-community-client-8.0.31-1.el7.x86_64.rpm                                                                                                                                                                                                   |  16 MB  00:00:06   
  45. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  46. Total                                                                                                                                                                                                                                          3.4 MB/s |  21 MB  00:00:06   
  47. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
  48. Importing GPG key 0x3A79BD29:
  49. Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
  50. Fingerprint: 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29
  51. Package    : mysql80-community-release-el7-5.noarch (@/mysql80-community-release-el7-5.noarch)
  52. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
  53. Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  54. Importing GPG key 0x5072E1F5:
  55. Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
  56. Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
  57. Package    : mysql80-community-release-el7-5.noarch (@/mysql80-community-release-el7-5.noarch)
  58. From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
  59. Running transaction check
  60. Running transaction test
  61. Transaction test succeeded
  62. Running transaction
  63.   Installing : mysql-community-client-plugins-8.0.31-1.el7.x86_64                                                                                                                                                                                                          1/6
  64.   Installing : mysql-community-common-8.0.31-1.el7.x86_64                                                                                                                                                                                                                  2/6
  65.   Installing : mysql-community-libs-8.0.31-1.el7.x86_64                                                                                                                                                                                                                    3/6
  66.   Installing : mysql-community-libs-compat-8.0.31-1.el7.x86_64                                                                                                                                                                                                             4/6
  67.   Installing : mysql-community-client-8.0.31-1.el7.x86_64                                                                                                                                                                                                                  5/6
  68.   Erasing    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                                                                                                          6/6
  69.   Verifying  : mysql-community-common-8.0.31-1.el7.x86_64                                                                                                                                                                                                                  1/6
  70.   Verifying  : mysql-community-client-plugins-8.0.31-1.el7.x86_64                                                                                                                                                                                                          2/6
  71.   Verifying  : mysql-community-libs-compat-8.0.31-1.el7.x86_64                                                                                                                                                                                                             3/6
  72.   Verifying  : mysql-community-client-8.0.31-1.el7.x86_64                                                                                                                                                                                                                  4/6
  73.   Verifying  : mysql-community-libs-8.0.31-1.el7.x86_64                                                                                                                                                                                                                    5/6
  74.   Verifying  : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                                                                                                          6/6
  75. Installed:
  76.   mysql-community-client.x86_64 0:8.0.31-1.el7                                             mysql-community-libs.x86_64 0:8.0.31-1.el7                                             mysql-community-libs-compat.x86_64 0:8.0.31-1.el7                                          
  77. Dependency Installed:
  78.   mysql-community-client-plugins.x86_64 0:8.0.31-1.el7                                                                                       mysql-community-common.x86_64 0:8.0.31-1.el7                                                                                    
  79. Replaced:
  80.   mariadb-libs.x86_64 1:5.5.68-1.el7                                                                                                                                                                                                                                          
  81. Complete!
复制代码
1.1.3 检察MySQL客户端版本

  1. [root@obproxy-node bin]# mysql --version
  2. mysql  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)
  3. [root@obproxy-node bin]# mysql --help
  4. mysql  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)
  5. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Usage: mysql [OPTIONS] [database]
  10.   -?, --help          Display this help and exit.
  11.   -I, --help          Synonym for -?
  12.   --auto-rehash       Enable automatic rehashing. One doesn't need to use
  13.                       'rehash' to get table and field completion, but startup
  14.                       and reconnecting may take a longer time. Disable with
  15.                       --disable-auto-rehash.
  16.                       (Defaults to on; use --skip-auto-rehash to disable.)
  17.   -A, --no-auto-rehash
  18.                       No automatic rehashing. One has to use 'rehash' to get
  19.                       table and field completion. This gives a quicker start of
  20.                       mysql and disables rehashing on reconnect.
  21.   --auto-vertical-output
  22.                       Automatically switch to vertical output mode if the
  23.                       result is wider than the terminal width.
  24. ..........................
复制代码
1.2、利用MySQL客户端毗连OceanBase数据库

  1. [admin@obproxy-node ~]$ mysql -h 10.110.xxx.xxx -uroot@sys#xxxx -pxxxx -P2883 -c -A oceanbase
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 1048577
  5. Server version: 5.6.25 OceanBase_CE 4.0.0.0 (r100000282022112511-dd289d2407609a88b1fcdf2be9e7c384cb8e19d0) (Built Nov 25 2022 11:58:08)
  6. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> show databases;
  12. +--------------------+
  13. | Database           |
  14. +--------------------+
  15. | information_schema |
  16. | LBACSYS            |
  17. | mysql              |
  18. | oceanbase          |
  19. | ORAAUDITOR         |
  20. | SYS                |
  21. | test               |
  22. +--------------------+
  23. 7 rows in set (0.10 sec)
  24. ----------加上--default_auth=mysql_native_pasowrd默认加密算法测试
  25. [admin@obproxy-node ~]$ mysql -h 10.110.3.154 -uroot@sys#obcluster -pob@Passwd -P2883 -c -A oceanbase --default_auth=mysql_native_pasowrd
  26. mysql: [Warning] Using a password on the command line interface can be insecure.
  27. Welcome to the MySQL monitor.  Commands end with ; or \g.
  28. Your MySQL connection id is 1048578
  29. Server version: 5.6.25 OceanBase_CE 4.0.0.0 (r100000282022112511-dd289d2407609a88b1fcdf2be9e7c384cb8e19d0) (Built Nov 25 2022 11:58:08)
  30. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  31. Oracle is a registered trademark of Oracle Corporation and/or its
  32. affiliates. Other names may be trademarks of their respective
  33. owners.
  34. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  35. mysql> quit
  36. Bye
  37. [admin@obproxy-node ~]$ mysql -h 10.110.3.154 -uroot@sys#obcluster -pob@Passwd -P2883 -c -A oceanbase --default_auth=caching_sha2_password
  38. mysql: [Warning] Using a password on the command line interface can be insecure.
  39. ERROR 1045 (42000): Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: NO)
复制代码
  根据OceanBase官网介绍,当利用MySQL 8.0客户端毗连OceanBase时,必要在毗连命令上加–default_auth=mysql_native_pasowrd,因MySQL 8.0和之前的版本有不同的加密算法,MySQL 8.0之前默认加密算法是 “mysql_native_password”,而 MySQL8.0 的默认加密算法是"caching_sha2_password"。
    但通过测试,利用MySQL 8.0客户端毗连OceanBase 4.0 社区版时,可以不加mysql_native_password也能正常毗连。
    我也测试了下OceanBase 3企业版,发现利用MySQL 8.0 也可以不用加 --default_auth=mysql_native_pasowrd能正常毗连OceanBase数据库,以下是测试毗连企业版。
  1. [admin@obproxy-node ~]$ mysql -h10.110.xxx.xxx -P2883 -uSYS@xxxx -pbbBB22__
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 1766586
  5. Server version: 5.6.25
  6. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> quit
  12. Bye
  13. [admin@obproxy-node ~]$ mysql -h10.110.xxx.xxx -P2883 -uSYS@xxx -pbbBB22__ --default_auth=mysql_native_pasowrd
  14. mysql: [Warning] Using a password on the command line interface can be insecure.
  15. Welcome to the MySQL monitor.  Commands end with ; or \g.
  16. Your MySQL connection id is 1766628
  17. Server version: 5.6.25
  18. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  19. Oracle is a registered trademark of Oracle Corporation and/or its
  20. affiliates. Other names may be trademarks of their respective
  21. owners.
  22. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  23. mysql> quit
  24. Bye
复制代码
二、通过 obclient毗连 OceanBase 数据库

2.1、安装obclient

obclient是一个交互式和批处置处罚查询工具,通过 obclient您可以毗连 OceanBase 数据库。利用obclient必要先提前安装OBClient工具。
可以通过如下两种方式来安装obclient工具:
♦ 通过yum 安装 OBClient客户端
  1.   yum install -y obclient
复制代码
♦ 通过OceanBase官网下载rpm包安装obclient
2.2、检察obclient版本信息
  1. [admin@obproxy-node ~]$ obclient --version
  2. obclient  Ver  Distrib 10.4.18-MariaDB, for Linux (x86_64) using readline 5.1
  3. [admin@obproxy-node ~]$ obclient --help
  4. obclient  Ver  Distrib 10.4.18-MariaDB, for Linux (x86_64) using readline 5.1
  5. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  6. Usage: obclient [OPTIONS] [database]
  7. Default options are read from the following files in the given order:
  8. /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
  9. The following groups are read: mysql mariadb-client client client-server client-mariadb
  10. The following options may be given as the first argument:
  11. --print-defaults          Print the program argument list and exit.
  12. --no-defaults             Don't read default options from any option file.
  13. The following specify which files/extra groups are read (specified before remaining options):
  14. --defaults-file=#         Only read default options from the given file #.
  15. --defaults-extra-file=#   Read this file after the global files are read.
  16. --defaults-group-suffix=# Additionally read default groups with # appended as a suffix.
  17.   -?, --help          Display this help and exit.
  18.   -I, --help          Synonym for -?
  19.   --abort-source-on-error
  20.                       Abort 'source filename' operations in case of errors
  21.   --auto-rehash       Enable automatic rehashing. One doesn't need to use
  22.                       'rehash' to get table and field completion, but startup
  23.                       and reconnecting may take a longer time. Disable with
  24.                       --disable-auto-rehash.
  25.                       (Defaults to on; use --skip-auto-rehash to disable.)
复制代码
2.3 利用obclient毗连OceanBase

  1. [admin@obproxy-node ~]$ obclient -h 10.110.xxx.xxx -uroot@sys#xxx -pob@Passwd -P2883 -c -A oceanbase
  2. Welcome to the OceanBase.  Commands end with ; or \g.
  3. Your OceanBase connection id is 14
  4. Server version: OceanBase_CE 4.0.0.0 (r100000282022112511-dd289d2407609a88b1fcdf2be9e7c384cb8e19d0) (Built Nov 25 2022 11:58:08)
  5. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. obclient [oceanbase]> show databases;
  8. +--------------------+
  9. | Database           |
  10. +--------------------+
  11. | information_schema |
  12. | LBACSYS            |
  13. | mysql              |
  14. | oceanbase          |
  15. | ORAAUDITOR         |
  16. | SYS                |
  17. | test               |
  18. +--------------------+
  19. 7 rows in set (0.277 sec)
  20. obclient [oceanbase]>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

饭宝

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表