Bug #93775 Global Variables db is null
Submitted: 2 Jan 2019 4:59 Modified: 24 Jan 2020 13:06
Reporter: xiangyunwangluo xiangyun Email Updates:
Status: Closed Impact on me:
None 
Category:Shell General / Core Client Severity:S3 (Non-critical)
Version:8.0.13 OS:MacOS (10.14.2)
Assigned to: CPU Architecture:Any

[2 Jan 2019 4:59] xiangyunwangluo xiangyun
Description:
when i input db in mysqlsh, return nothing. but input dba, return <Dba>. 

How to repeat:
install mysql shell use https://dev.mysql.com/get/Downloads/MySQL-Shell/mysql-shell-8.0.13-macos10.14-x86-64bit.dm....
[2 Jan 2019 5:03] xiangyunwangluo xiangyun
my action

Attachment: 1546405304380.jpg (image/jpeg, text), 126.74 KiB.

[2 Jan 2019 10:20] MySQL Verification Team
Hello Xiangyun,

Thank you for the report.
Quoting from the manual "db represents a schema if one has been defined, for example by a URI type string."  https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-global-variables.html

Looking at your screenshot "no default" schema was selected and hence you are seeing it blank. Could you please attempt below steps and confirm if you are still seeing blank? 

bin/mysqlsh root@localhost:33330
Creating a session to 'root@localhost:33330'
Please provide the password for 'root@localhost:33330':
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 8 (X protocol)
Server version: 8.0.13 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL Shell 8.0.13

Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.

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.

 MySQL  localhost:33330+ ssl  JS > db
 MySQL  localhost:33330+ ssl  JS > dba
<Dba>

 MySQL  localhost:33330+ ssl  JS > \use mysql
Default schema `mysql` accessible through db.

 MySQL  localhost:33330+ ssl  mysql  JS > db
<Schema:mysql>

 MySQL  localhost:33330+ ssl  mysql  JS >

regards,
Umesh
[5 Jan 2019 3:03] xiangyunwangluo xiangyun
Hello Umesh Shastry,

Thank you for your work.

i do follow yours as below。

but it does not work.

xizi@xian  ~  mysqlsh  root@localhost:3307/mysql
Creating a session to 'root@localhost:3307/mysql'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 119
Server version: 8.0.13 MySQL Community Server - GPL
Default schema set to `mysql`.
MySQL Shell 8.0.13

Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.

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.

 MySQL  localhost:3307 ssl  mysql  JS > db
 MySQL  localhost:3307 ssl  mysql  JS > \exit
Bye!

OR as below

xizi@xian   ~  mysqlsh  root@localhost:3307
Creating a session to 'root@localhost:3307'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 121
Server version: 8.0.13 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL Shell 8.0.13

Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.

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.

 MySQL  localhost:3307 ssl  JS > \use mysql
Default schema set to `mysql`.

 MySQL  localhost:3307 ssl  mysql  JS > db
 MySQL  localhost:3307 ssl  mysql  JS >

Thank you again!
[7 Jan 2019 6:02] MySQL Verification Team
Thank you for the feedback.

regards,
Umesh
[12 Nov 2019 11:26] Juan Rene Ramirez Monarrez
Posted by developer:
 
Hi Guys

First of all thanks for submitting the report, however, it works as designed.

As you know, the API objects available in the shell depend on the protocol being used, a full development API is only available in the X protocol, where among other things we have an object that represents a schema which provides functions for several operations on the schema:

https://dev.mysql.com/doc/dev/mysqlsh-api-javascript/8.0/classmysqlsh_1_1mysqlx_1_1_schema...

However, when it comes to the MySQL Protocol (What we call the classic protocol) the API interface is minimal and only supports SQL execution, there's no Schema object, just ClassicSession which allows executing SQL and ClassicResult which allows retrieving the data:

https://dev.mysql.com/doc/dev/mysqlsh-api-javascript/8.0/group___shell_a_p_i.html

This is documented on the description of the "db" object at the API User Guide: https://dev.mysql.com/doc/dev/mysqlsh-api-javascript/8.0/

However, while reviewing this, I noted it is NOT mentioned on the user guide: https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-global-variables.html

We will use this bug report to fix the user guide instead.
[24 Jan 2020 13:06] Margaret Fisher
Posted by developer:
 
The information at
https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-global-variables.html
now provides a full description of the conditions for the db global object:

db is available when the global session was established using an X Protocol connection with a default database specified, and represents that schema. 

Thanks for reporting this and helping us to improve the documentation!