MySQL Shell API 26.10.0
Unified development interface for MySQL Products
Classes | Functions

Encloses the functions and classes available to interact with a MySQL Server using the traditional MySQL Protocol. More...

Classes

class  Type
 Constants to represent data types on Column objects. More...
 

Functions

ClassicSession getClassicSession (ConnectionData connectionData, String password)
 Opens a classic MySQL protocol session to a MySQL server. More...
 
ClassicSession getSession (ConnectionData connectionData, String password)
 Opens a classic MySQL protocol session to a MySQL server. More...
 
Array splitScript (String script, Dictionary options)
 Split a SQL script into individual statements. More...
 
Dictionary parseStatementAst (String statements, Dictionary options)
 Parse MySQL statements and return its AST representation. More...
 
Dictionary parseDdlScript (String script, Dictionary options)
 Parse DDL statements and return the detected object changes. More...
 
Dictionary parseDataType (String typeDefinition)
 Parse a MySQL data type definition. More...
 
Array tokenizeStatement (String statement, Dictionary options)
 Lexes a MySQL statement into a list of tokens. More...
 
String quoteIdentifier (String s)
 Quote a string as a MySQL identifier, escaping characters when needed. More...
 
String quoteString (String s)
 Quote a string as a MySQL string literal, escaping characters when needed. More...
 
String unquoteIdentifier (String s)
 Unquote a MySQL identifier. More...
 
String unquoteString (String s)
 Unquote a MySQL string literal. More...
 
String makeAccount (String user, String host)
 Joins user and host into an quoted account string. More...
 
Dictionary splitAccount (String account)
 Splits account string into user and host. More...
 

Detailed Description

Encloses the functions and classes available to interact with a MySQL Server using the traditional MySQL Protocol.

Use this module to create a session using the traditional MySQL Protocol, for example for MySQL Servers where the X Protocol is not available.

Note that the API interface on this module is very limited, even you can load schemas, tables and views as objects there are no operations available on them.

The purpose of this module is to allow SQL Execution on MySQL Servers where the X Protocol is not enabled.

To use the properties and functions available on this module you first need to import it.

mysql-js> var mysql = require('mysql');
// Then you can use the module functions and properties
// for example to create a session
mysql-js> var mySession = mysql.getClassicSession('admin@localhost');
Any require(String module_name_or_path)
Loads the specified JavaScript module.
Definition: mod_shell.cc:73

When running the shell in interactive mode, this module is automatically imported.

Function Documentation

◆ getClassicSession()

ClassicSession getClassicSession ( ConnectionData  connectionData,
String  password 
)

Opens a classic MySQL protocol session to a MySQL server.

Parameters
connectionDataThe connection data for the session
passwordOptional password for the session
Returns
A ClassicSession

A ClassicSession object uses the traditional MySQL Protocol to allow executing operations on the connected MySQL Server.

Connection Data

The connection data may be specified in the following formats:

  • A URI string
  • A dictionary with the connection options

A basic URI string has the following format:

[scheme://][user[:password]@]<host[:port]|socket>[/schema][?option=value&option=value...]

For additional information about MySQL connection data, see Connection Data.

◆ getSession()

ClassicSession getSession ( ConnectionData  connectionData,
String  password 
)

Opens a classic MySQL protocol session to a MySQL server.

Parameters
connectionDataThe connection data for the session
passwordOptional password for the session
Returns
A ClassicSession

A ClassicSession object uses the traditional MySQL Protocol to allow executing operations on the connected MySQL Server.

Connection Data

The connection data may be specified in the following formats:

  • A URI string
  • A dictionary with the connection options

A basic URI string has the following format:

[scheme://][user[:password]@]<host[:port]|socket>[/schema][?option=value&option=value...]

For additional information about MySQL connection data, see Connection Data.

◆ splitScript()

Array splitScript ( String  script,
Dictionary  options 
)

Split a SQL script into individual statements.

Parameters
scriptA SQL script as a string containing multiple statements
optionsOptional dictionary of parser options
Returns
A list of statements

The default statement delimiter is `;` but it can be changed with the DELIMITER keyword, which must be followed by the delimiter character(s) and a newline.

Supported options are:

  • ansiQuotes: if true, treat `"` as an identifier quote
  • noBackslashEscapes: if true, backslashes do not escape characters in strings

◆ parseStatementAst()

Dictionary parseStatementAst ( String  statements,
Dictionary  options 
)

Parse MySQL statements and return its AST representation.

Parameters
statementsSQL statements to be parsed
optionsOptional dictionary of parser options
Returns
AST encoded as a JSON structure

Supported options are:

  • ansiQuotes: if true, treat `"` as an identifier quote
  • noBackslashEscapes: if true, backslashes do not escape characters in strings

◆ parseDdlScript()

Dictionary parseDdlScript ( String  script,
Dictionary  options 
)

Parse DDL statements and return the detected object changes.

Parameters
scriptSQL script with DDL statements
optionsOptional dictionary of parser options
Returns
Dictionary with parsed DDL changes

Supported options are:

  • schema: default schema for unqualified object names
  • ignoreErrors: if true, ignore statements that cannot be parsed
  • version: MySQL server version to parse against; defaults to Shell version
  • ansiQuotes: if true, treat `"` as an identifier quote. Default is false.
  • noBackslashEscapes: if true, backslashes do not escape characters in strings. Default is false.

◆ parseDataType()

Dictionary parseDataType ( String  typeDefinition)

Parse a MySQL data type definition.

Parameters
typeDefinitionMySQL data type definition
Returns
Dictionary with the parsed type, precision, scale, length, explicit parameters, and flags. Absent precision, scale, and length values are null.

◆ tokenizeStatement()

Array tokenizeStatement ( String  statement,
Dictionary  options 
)

Lexes a MySQL statement into a list of tokens.

Parameters
statementSQL statement to be tokenized
optionsOptional dictionary of tokenizer options
Returns
A list of objects with type and token fields

Supported options are:

  • ansiQuotes: if true, treat `"` as an identifier quote
  • noBackslashEscapes: if true, backslashes do not escape characters in strings

◆ quoteIdentifier()

String quoteIdentifier ( String  s)

Quote a string as a MySQL identifier, escaping characters when needed.

Parameters
sthe identifier name to be quoted
Returns
Quoted identifier

◆ quoteString()

String quoteString ( String  s)

Quote a string as a MySQL string literal, escaping characters when needed.

Parameters
sthe string value to be quoted
Returns
Quoted string

◆ unquoteIdentifier()

String unquoteIdentifier ( String  s)

Unquote a MySQL identifier.

Parameters
sString to unquote
Returns
Unquoted string.

An exception is thrown if the input string is not quoted with backticks.

◆ unquoteString()

String unquoteString ( String  s)

Unquote a MySQL string literal.

Parameters
sString to unquote
Returns
Unquoted string

◆ makeAccount()

String makeAccount ( String  user,
String  host 
)

Joins user and host into an quoted account string.

Parameters
userUser name to join
hostHost name to join
Returns
Quoted account string.

◆ splitAccount()

Dictionary splitAccount ( String  account)

Splits account string into user and host.

Parameters
accountAccount string
Returns
Dictionary with user and host strings