绝了...玩转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 > 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值