MySQL Shell uses a default prompt for both Python (
mysql-py> ) and JavaScript (
mysql-js> ).
You can customize the language specific prompt using the
shell.custom_prompt() function. This function
must return a string that is used as the prompt. To have a custom
prompt when MySQL Shell starts, define this function in a
startup script. The following example shows how this functionality
can be used.
In Python shell.custom_prompt() could be
defined as:
# Import the sys module
from time import gmtime, strftime
def my_prompt():
ret_val = strftime("%H:%M:%S", gmtime())
if session and session.isOpen():
data = shell.parseUri(session.getUri())
ret_val = "%s-%s-%s-py> " % (ret_val, data.dbUser, data.host)
else:
ret_val = "%s-disconnected-py> " % ret_val
return ret_val
shell.custom_prompt = my_prompt
In JavaScript shell.custom_prompt() could be
defined as:
shell.custom_prompt = function(){
var now = new Date();
var ret_val = now.getHours().toString()+ ":" + now.getMinutes().toString() + ":" + now.getSeconds().toString();
if (session && session.isOpen()){
var data = shell.parseUri(session.getUri());
ret_val += "-" + data.dbUser + "-" + data.host + "-js> ";
}
else
ret_val += "-disconnected-js> ";
return ret_val;
}The following example demonstrates using the custom prompt functions defined above in startup script. The prompts show the current system time, and if a session is open the current user and host:
Welcome to MySQL Shell 1.0.4 Development Preview
Copyright (c) 2016, 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', '\h' or '\?' for help.
Currently in JavaScript mode. Use \sql to switch to SQL mode and execute queries.
14:34:32-disconnected-js> \py
Switching to Python mode...
19:34:39-disconnected-py> \connect root:@localhost
Creating an X Session to root@localhost:33060
No default schema selected.
19:34:50-root-localhost-py> \js
Switching to JavaScript mode...
14:34:57-root-localhost-js>