IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> 绝了...玩转MySQL Shell -> 正文阅读

[大数据]绝了...玩转MySQL Shell

? 1.Connecting to MySQL Server with MySQL Shell

[root@MaxwellDBA ~]# 
[root@MaxwellDBA ~]# mysqlsh --host=127.0.0.1 --port=33060 --user=cbuser --schema=cookbook
Please provide the password for 'cbuser@127.0.0.1:33060': ******
Save password for 'cbuser@127.0.0.1:33060'? [Y]es/[N]o/Ne[v]er (default No): y
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'cbuser@127.0.0.1:33060/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 212 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > connectionData={
                                          -> "host": "127.0.0.1",
                                          -> "user": "cbuser",
                                          -> "schema": "cookbook"
                                          -> }
                                          -> 
{
    "host": "127.0.0.1", 
    "schema": "cookbook", 
    "user": "cbuser"
}
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > shell.connect(connectionData)
Creating a session to 'cbuser@127.0.0.1/cookbook'
Please provide the password for 'cbuser@127.0.0.1': ******
Save password for 'cbuser@127.0.0.1'? [Y]es/[N]o/Ne[v]er (default No): y
Fetching schema names for autocompletion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 213 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
<Session:cbuser@127.0.0.1:33060>
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > exit
ReferenceError: exit is not defined
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > quit
ReferenceError: quit is not defined
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > \quit
Bye!
[root@MaxwellDBA ~]# mysqlsh mysqlx://cbuser:cbpass@127.0.1/cookbook
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating an X protocol session to 'cbuser@127.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 214 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.1:33060+ ssl  cookbook  JS > \quit
Bye!
[root@MaxwellDBA ~]# mysqlsh mysqlx://cbuser@127.0.1/cookbook       
Please provide the password for 'cbuser@127.0.1': ******
Save password for 'cbuser@127.0.1'? [Y]es/[N]o/Ne[v]er (default No): y
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating an X protocol session to 'cbuser@127.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 215 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.1:33060+ ssl  cookbook  JS > 

? Selecting the protocol

[root@MaxwellDBA ~]# 
[root@MaxwellDBA ~]# mysqlsh --host=127.0.0.1 --user=cbuser --schema=cookbook --mysqlx
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating an X protocol session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 217 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > \q
Bye!
[root@MaxwellDBA ~]# mysqlsh --host=127.0.0.1 --user=cbuser --schema=cookbook --mysql
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a Classic session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 218
Server version: 8.0.26 Source distribution
Default schema set to `cookbook`.
 MySQL  127.0.0.1:3306 ssl  cookbook  JS > connectionData={
                                        -> "schema":"mysql","host":"127.0.0.1",
                                        -> "user":"cbuser","schema":"cookbook"
                                        -> }
                                        -> 
{
    "host": "127.0.0.1", 
    "schema": "cookbook", 
    "user": "cbuser"
}
 MySQL  127.0.0.1:3306 ssl  cookbook  JS > \q
Bye!
[root@MaxwellDBA ~]# mysqlsh mysqlx://cbuser:cbpass@127.0.0.1/cookbook
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating an X protocol session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 221 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > \q
Bye!
[root@MaxwellDBA ~]# mysqlsh mysql://cbuser:cbpass@127.0.0.1/cookbook
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a Classic session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 223
Server version: 8.0.26 Source distribution
Default schema set to `cookbook`.
 MySQL  127.0.0.1:3306 ssl  cookbook  JS > 
 MySQL  127.0.0.1:3306 ssl  cookbook  JS > \c mysql://cbuser:cbpass@127.0.0.1/cookbook
Creating a Classic session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Closing old connection...
Your MySQL connection id is 224
Server version: 8.0.26 Source distribution
Default schema set to `cookbook`.
 MySQL  127.0.0.1:3306 ssl  cookbook  JS > \q
Bye!
[root@MaxwellDBA ~]# mysqlsh --host=127.0.0.1 --port=33060 --user=cbuser --schema=cookbook --mx
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating an X protocol session to 'cbuser@127.0.0.1:33060/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 225 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > shell.status()
MySQL Shell version 8.0.29

Connection Id:                225
Default schema:               cookbook
Current schema:               cookbook
Current user:                 cbuser@localhost
SSL:                          Cipher in use: TLS_AES_256_GCM_SHA384 TLSv1.3
Using delimiter:              ;
Server version:               8.0.26 Source distribution
Protocol version:             X protocol
Client library:               8.0.29
Connection:                   127.0.0.1 via TCP/IP
TCP port:                     33060
Server characterset:          utf8mb4
Schema characterset:          utf8mb4
Client characterset:          utf8mb4
Conn. characterset:           utf8mb4
Result characterset:          utf8mb4
Compression:                  Enabled (DEFLATE_STREAM)
Uptime:                       2 days 2 hours 18 min 9.0000 sec


 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 

Selecting SQL,JavaScript, or Python Mode

[root@MaxwellDBA ~]# mysqlsh cbuser:cbpass@127.0.0.1/cookbook --py                               
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 226 (X protocol)
Server version: 8.0.26 Source distribution
Default schema `cookbook` accessible through db.
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > \js
Switching to JavaScript mode...
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > \py
Switching to Python mode...
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > \sql
Switching to SQL mode... Commands end with ;
Fetching table and column names from `cookbook` for auto-completion... Press ^C to stop.
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > 

Running SQL Session

[root@MaxwellDBA ~]# 
[root@MaxwellDBA ~]# mysqlsh cbuser:cbpass@127.0.0.1/cookbook --sql
MySQL Shell 8.0.29

Copyright (c) 2016, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a session to 'cbuser@127.0.0.1/cookbook'
Fetching schema names for autocompletion... Press ^C to stop.
Fetching table and column names from `cookbook` for auto-completion... Press ^C to stop.
Your MySQL connection id is 227 (X protocol)
Server version: 8.0.26 Source distribution
Default schema set to `cookbook`.
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > delimiter | 
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > CREATE PROCEDURE get_client_info()
                                           -> BEGIN
                                           -> SELECT GROUP_CONCAT(ATTR_NAME,'=',ATTR_VALUE)
                                           -> FROM performance_schema.session_account_connect_attrs
                                           -> WHERE ATTR_NAME IN ('_client_name','_client_version');
                                           -> END
                                           -> |
Query OK, 0 rows affected (0.0052 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > delimiter;
ERROR: DELIMITER must be followed by a 'delimiter' character or string
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > delimiter ;
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > CALL get_client_info();
+-----------------------------------------------------+
| GROUP_CONCAT(ATTR_NAME,'=',ATTR_VALUE)              |
+-----------------------------------------------------+
| _client_name=libmysqlxclient,_client_version=8.0.29 |
+-----------------------------------------------------+
1 row in set (0.0028 sec)

Query OK, 0 rows affected (0.0028 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > 

Running SQL in JavaScript Mode

Use the \sql command , or use the sql() and runSQL() methods that belong to the Session class.

 MySQL  127.0.0.1:33060+ ssl  cookbook  SQL > \js
Switching to JavaScript mode...
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > \sql SELECT * FROM limbs WHERE arms >=2 ORDER BY arms;
+--------------+------+------+
| thing        | legs | arms |
+--------------+------+------+
| armchair     |    4 |    2 |
| human        |    2 |    2 |
| Peg Leg Pete |    1 |    2 |
| squid        |    0 |   10 |
+--------------+------+------+
4 rows in set (0.0008 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > session.runSql(
                                          -> "SELECT * FROM limbs WHERE arms >=2 ORDER BY arms")
                                          -> 
+--------------+------+------+
| thing        | legs | arms |
+--------------+------+------+
| armchair     |    4 |    2 |
| human        |    2 |    2 |
| Peg Leg Pete |    1 |    2 |
| squid        |    0 |   10 |
+--------------+------+------+
4 rows in set (0.0007 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 

Running SQL in Python Mode

 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > \sql SELECT * FROM movies;
+----+------+----------------------------+
| id | year | movie                      |
+----+------+----------------------------+
|  1 | 1997 | The Fifth Element          |
|  2 | 1999 | The Phantom Menace         |
|  3 | 2001 | The Fellowship of the Ring |
|  4 | 2005 | Kingdom of Heaven          |
|  5 | 2010 | Red                        |
|  6 | 2011 | Unknown                    |
+----+------+----------------------------+
6 rows in set (0.0007 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.run_sql("SELECT * FROM movies WHERE year < ?",[2000])
+----+------+--------------------+
| id | year | movie              |
+----+------+--------------------+
|  1 | 1997 | The Fifth Element  |
|  2 | 1999 | The Phantom Menace |
+----+------+--------------------+
2 rows in set (0.0007 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py >

Working with Tables in JavaScript Mode

 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > session.getDefaultSchema().getTable('limbs').select()
+--------------+------+------+
| thing        | legs | arms |
+--------------+------+------+
| armchair     |    4 |    2 |
| centipede    |   99 |    0 |
| fish         |    0 |    0 |
| human        |    2 |    2 |
| insect       |    6 |    0 |
| Peg Leg Pete |    1 |    2 |
| phonograph   |    0 |    1 |
| space alien  | NULL | NULL |
| squid        |    0 |   10 |
| table        |    4 |    0 |
| tripod       |    3 |    0 |
+--------------+------+------+
11 rows in set (0.0006 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > session.getDefaultSchema().getTable('limbs').select().where('legs >= :legs').orderBy('legs').bind('legs', 4)
+-----------+------+------+
| thing     | legs | arms |
+-----------+------+------+
| armchair  |    4 |    2 |
| table     |    4 |    0 |
| insect    |    6 |    0 |
| centipede |   99 |    0 |
+-----------+------+------+
4 rows in set (0.0007 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs = session.getDefaultSchema().getTable('limbs')
<Table:limbs>
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > session.startTransaction()
Query OK, 0 rows affected (0.0003 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.insert('thing','legs','arms').values('cat', 4, 0).values('dog', 2, 2)
Query OK, 2 items affected (0.0009 sec)

Records: 2  Duplicates: 0  Warnings: 0
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.count()
13
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.update().set('legs', 4).set('arms', 0).where("thing='dog'")
Query OK, 1 item affected (0.0008 sec)

Rows matched: 1  Changed: 1  Warnings: 0
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.select().where("thing='dog'")
+-------+------+------+
| thing | legs | arms |
+-------+------+------+
| dog   |    4 |    0 |
+-------+------+------+
1 row in set (0.0008 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.delete().where("thing='cat'")
Query OK, 1 item affected (0.0009 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.count()
12
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > session.rollback()
Query OK, 0 rows affected (0.0016 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.count()
11
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > limbs.select().where("thing='dog' or thing='cat'")
Empty set (0.0008 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 

Working with Tables in Python Mode

 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.get_schema('cookbook').get_table('movies').select()
+----+------+----------------------------+
| id | year | movie                      |
+----+------+----------------------------+
|  1 | 1997 | The Fifth Element          |
|  2 | 1999 | The Phantom Menace         |
|  3 | 2001 | The Fellowship of the Ring |
|  4 | 2005 | Kingdom of Heaven          |
|  5 | 2010 | Red                        |
|  6 | 2011 | Unknown                    |
+----+------+----------------------------+
6 rows in set (0.0005 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies=session.get_schema('cookbook').get_table('movies')
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies_actors=session.get_schema('cookbook').get_table('movies_actors')
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.start_transaction()
Query OK, 0 rows affected (0.0003 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies.insert('year', 'movie').values(2017, 'Darkest Hour')
Query OK, 1 item affected (0.0009 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies_actors.insert().values(1997, 'Darkest Hour', 'Gary Oldman')
Query OK, 1 item affected (0.0008 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.commmit()
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: unknown attribute: commmit
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.commit()
Query OK, 0 rows affected (0.0025 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.sql("SELECT * FROM movies JOIN movies_actors USING(movie) WHERE actor = 'Gary Oldman'")
+-------------------+----+------+------+-------------+
| movie             | id | year | year | actor       |
+-------------------+----+------+------+-------------+
| The Fifth Element |  1 | 1997 | 1997 | Gary Oldman |
| Darkest Hour      |  8 | 2017 | 1997 | Gary Oldman |
+-------------------+----+------+------+-------------+
2 rows in set (0.0010 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.start_transaction()
Query OK, 0 rows affected (0.0003 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies.update().set('year',2017).where("movie='Darest Hour'")
Query OK, 0 items affected (0.0008 sec)

Rows matched: 0  Changed: 0  Warnings: 0
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies_actors.update().set('year',2017).where("movie='Darest Hour'")
Query OK, 0 items affected (0.0008 sec)

Rows matched: 0  Changed: 0  Warnings: 0
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.start_transaction()
Query OK, 0 rows affected (0.0004 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies.delete().where("movie='Darkest Hour'")
Query OK, 1 item affected (0.0008 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > movies_actors.delete().where("movie='Darkest Hour'")
Query OK, 1 item affected (0.0008 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > session.commit()
Query OK, 0 rows affected (0.0026 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  Py > 

Working with Collections in JavaScript Mode

 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > collectionlimbs=session.getCurrentSchema().createCollection('CollectionLimbs')
<Collection:CollectionLimbs>
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > session.getCurrentSchema().dropCollection('collectionLimbs')
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > schema={
                                          ->     "$schema": "http://json-schema.org/draft-07/schema",
                                          ->     "id": "http://example.com/cookbook.json",
                                          ->     "type":"object",
                                          ->     "description":"Table limbs as a collection",
                                          ->     "properties":{
                                          ->         "thing": {"type": "string"},
                                          ->         "legs": {
                                          ->             "anyOf":[{"type": "number"},{"type": "null"}],
                                          ->             "default": 0
                                          ->         },
                                          ->         "arms":{
                                          ->             "anyOf": [{"type": "number"},{"type": "null"}],
                                          ->             "default": 0
                                          ->         },
                                          ->         "required":["thing","legs","arms"]
                                          ->     }
                                          -> 
                                          -> 

 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > collectionLimbs=session.getCurrentSchema().createCollection('collectionLimbs',{"validation": {"level": "strict", "schema": schema}})

Controlling the Output Format

 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > \option resultFormat=tabbed
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > artist=session.getCurrentSchema().getTable('artist')
<Table:artist>
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > artist.select()
a_id    name
1       Da Vinci
2       Monet
4       Renoir
3       Van Gogh
4 rows in set (0.0009 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > shell.options.set('resultFormat','vertical')
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > artist.select()
*************************** 1. row ***************************
a_id: 1
name: Da Vinci
*************************** 2. row ***************************
a_id: 2
name: Monet
*************************** 3. row ***************************
a_id: 4
name: Renoir
*************************** 4. row ***************************
a_id: 3
name: Van Gogh
4 rows in set (0.0006 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > shell.options.set('resultFormat','json')
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > artist.select()
{
    "a_id": 1,
    "name": "Da Vinci"
}
{
    "a_id": 2,
    "name": "Monet"
}
{
    "a_id": 4,
    "name": "Renoir"
}
{
    "a_id": 3,
    "name": "Van Gogh"
}
4 rows in set (0.0006 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > shell.options.set('resultFormat','json/raw')
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > artist.select()
{"a_id":1,"name":"Da Vinci"}
{"a_id":2,"name":"Monet"}
{"a_id":4,"name":"Renoir"}
{"a_id":3,"name":"Van Gogh"}
4 rows in set (0.0006 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > shell.options.set('resultFormat','json/array')
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > artist.select()
[
{"a_id":1,"name":"Da Vinci"},
{"a_id":2,"name":"Monet"},
{"a_id":4,"name":"Renoir"},
{"a_id":3,"name":"Van Gogh"}
]
4 rows in set (0.0009 sec)
 MySQL  127.0.0.1:33060+ ssl  cookbook  JS > 
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-10-17 12:41:07  更:2022-10-17 12:43:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/18 14:23:02-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码