MySQL Shell8.0数据库命令_\connect root@localhost-程序员宅基地

技术标签: MySQL Shell  MySQL  数据库  数据库命令  

伴随MySQL8.0同时发布了MySQL Shell,这款神器具有支持多种语言(JS、python、SQL),交互式界面,多行批量执行等特点。

MySQL Shell 命令

命令 简写/别名 描述
\help \h or \? 显示帮助信息
\quit \q or \exit 退出
\ SQL模式中,“\”分割多行代码以缓冲执行
\status \s 显示MySQL当前状态
\js 转换到JavaScript执行模式
\py 转换到Python执行模式
\sql 转换到SQL执行模式
\connect \c 连接到SQL服务器
\reconnect 重连至同一个MySQL服务器
\use \u 指定要用的图表
\source . 执行当前语言编写的脚本文件
\warnings \W 显示一个声明生成的警告
\nowarnings \w 不显示任何警告
\history 查看和编辑之前的命令行
\rehash 手动更新自动完成名称缓存
Help命令

\help

The Shell Help is organized in categories and topics. To get help for
a specific category or topic use: \?

The argument should be the name of a category or a topic.

The pattern is a filter to identify topics for which help is required,
it can use the following wildcards:

  • ? matches any single charecter.
    • matches any character sequence.

The following are the main help categories:

  • AdminAPI Introduces to the dba global object and the InnoDB cluster
    administration API.
  • Shell Commands Provides details about the available built-in shell commands.
  • ShellAPI Contains information about the shell and util global objects
    as well as the mysql module that enables executing SQL on
    MySQL Servers.
  • SQL Syntax Entry point to retrieve syntax help on SQL statements.
  • X DevAPI Details the mysqlx module as well as the capabilities of the
    X DevAPI which enable working with MySQL as a Document Store

The available topics include:

  • The dba global object and the classes available at the AdminAPI.
  • The mysqlx module and the classes available at the X DevAPI.
  • The mysql module and the global objects and classes available at the ShellAPI.
  • The functions and properties of the classes exposed by the APIs.
  • The available shell commands.
  • Any word that is part of an SQL statement.

SHELL COMMANDS

The shell commands allow executing specific operations including
updating the shell configuration.

The following shell commands are available:

  • \ Start multi-line input when in SQL mode.
  • \connect (\c) Connects the shell to a MySQL server and assigns the
    global session.
  • \exit Exits the MySQL Shell, same as \quit.
  • \help (\?,\h) Prints help information about a specific topic.
  • \history View and edit command line history.
  • \js Switches to JavaScript processing mode.
  • \nowarnings (\w) Don’t show warnings after every statement.
  • \option Allows working with the available shell options.
  • \py Switches to Python processing mode.
  • \quit (\q) Exits the MySQL Shell.
  • \reconnect Reconnects the global session.
  • \rehash Refresh the autocompletion cache.
  • \source (.) Loads and executes a script from a file.
  • \sql Switches to SQL processing mode.
  • \status (\s) Print information about the current global session.
  • \use (\u) Sets the active schema.
  • \warnings (\W) Show warnings after every statement.

GLOBAL OBJEECTS

The following modules and objects are ready for use when the shell
starts:

  • dba Used for InnoDB cluster administration.
  • mysql Support for connecting to MySQL servers using the classic MySQL
    protocol.
  • mysqlx Used to work with X Protocol sessions using the MySQL X DevAPI.
  • session Represents the currently open MySQL session.
  • shell Gives access to general purpose functions and properties.
  • sys Gives access to system specific parameters.
  • util Global object that groups miscellaneous tools like upgrade checker.

For additional information on these global objects use:
.help()

EXAMPLES \? AdminAPI
Displays information about the AdminAPI.

\? \connect
Displays usage details for the \connect command.

\? checkInstanceConfiguration
Displays usage details for the dba.checkInstanceConfiguration function.

\? sql syntax
Displays the main SQL help categories.

\help命令可以有以下参数

  • AdminAPI :引入dba全局对象及InnoDB cluster AdminAPI。如: \? dba。

    如:\? AdminAPI

显示: MySQL InnoDB cluster provides a complete high availability solution for MySQL. The AdminAPI is an interactive API that enables configuring and administering InnoDB clusters. Use the dba global object to: - Verify if a MySQL server is suitable for InnoDB cluster.- Configure a MySQL server to be used as an InnoDB cluster instance.- Create an InnoDB cluster.

\? dba

NAME

  dba - Global variable for InnoDB cluster management.

  The global variable dba is used to access the AdminAPI functionality and
  perform DBA operations. It is used for managing MySQL InnoDB clusters.

PROPERTIES

  verbose
        Enables verbose mode on the dba operations.

FUNCTIONS

  checkInstanceConfiguration(instance[, options])
        Validates an instance for MySQL InnoDB Cluster usage.

  configureInstance([instance][, options])
        Validates and configures an instance for MySQL InnoDB Cluster
        usage.

  configureLocalInstance(instance[, options])
        Validates and configures a local instance for MySQL InnoDB Cluster
        usage.

  createCluster(name[, options])
        Creates a MySQL InnoDB cluster.

  deleteSandboxInstance(port[, options])
        Deletes an existing MySQL Server instance on localhost.

  deploySandboxInstance(port[, options])
        Creates a new MySQL Server instance on localhost.

  dropMetadataSchema(options)
        Drops the Metadata Schema.

  getCluster([name][, options])
        Retrieves a cluster from the Metadata Store.

  help([member])
        Provides help about this object and it's members

  killSandboxInstance(port[, options])
        Kills a running MySQL Server instance on localhost.

  rebootClusterFromCompleteOutage([clusterName][, options])
        Brings a cluster back ONLINE when all members are OFFLINE.

  startSandboxInstance(port[, options])
        Starts an existing MySQL Server instance on localhost.

  stopSandboxInstance(port[, options])
        Stops a running MySQL Server instance on localhost.

  For more help on a specific function use: dba.help('<functionName>')

  e.g. dba.help('deploySandboxInstance')
  • Shell命令 :提供内置于MySQL Shell命令的细节。
  • ShellAPI :包含shell和util全局对象的信息,比如在MySQL服务器上执行SQL语言的mysql模块。
  • SQL语法 :SQL语句上的语法help信息。
  • X DevAPI:mysqlx模块及作为文档库与MySQL共同起作用的X DevAPI。
MySQL Shell连接/重连命令

连接mysql服务器,首先确保mysql服务器开启,Windows用户可以查看本地服务mysql手动开启,也可以通过命令行在Windows shell中应用‘’net start mysql‘’命令开启。MySQL Shell连接命令如下:
\connect命令后面跟一个URL字符串连接MySQL服务器。

\connect root@localhost:3306

也可以用–mysqlx (–mx) 选项创建基于X协议连接至MySQL服务器实例的会话:

\connect --mysqlx root@localhost:33060

还可以用–mysql (–mc)选项创建类会话ClassicSession,可以用MySQL协议直接连接服务器:

\connect --mysql root@localhost:3306

连接成功显示:

\connect root@localhost:3306

Creating a session to ‘root@localhost:3306’ Fetching schema names for
autocompletion… Press ^C to stop. Closing old connection… Your
MySQL connection id is 32 Server version: 8.0.12 MySQL Community
Server - GPL No default schema selected; type \use to set
one.

连接断掉可以用\reconnect重新连接,不用加任何参数。

source命令

\source用来执行指定路径的脚本文件代码:

\source /tmp/mydata.sql

在相应模式下可以执行SQL、JavaScript或Python任一种语言代码,当然用MySQL Shell执行SQL代码必须要在SQL模式下的。

\use 命令

要求活动的全局发展会话,\use命令将当前图表设置为特定的schema_name ,并将db变量更新到代表所选图表的对象中。

\use schema_name 
\history命令
  • \history save 用以存储历史记录
  • \history delete entrynumber 用以删除给定序号的历史条目
  • \history delete firstnumber-[lastnumber] 用以删除指定范围的历史条目
  • \history clear 用以清空历史记录
Rehash命令

\rehash 手动更新缓存,比如\use schema下载了一个新的图表到内存,\rehash更新自动完成的缓存。

Pager命令

可以设置MySQL Shell用一个外部的Pager命令来显示屏幕输出,如在线帮助或SQL检索结果。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/IT_ER/article/details/82593674

智能推荐

c# 调用c++ lib静态库_c#调用lib-程序员宅基地

文章浏览阅读2w次,点赞7次,收藏51次。四个步骤1.创建C++ Win32项目动态库dll 2.在Win32项目动态库中添加 外部依赖项 lib头文件和lib库3.导出C接口4.c#调用c++动态库开始你的表演...①创建一个空白的解决方案,在解决方案中添加 Visual C++ , Win32 项目空白解决方案的创建:添加Visual C++ , Win32 项目这......_c#调用lib

deepin/ubuntu安装苹方字体-程序员宅基地

文章浏览阅读4.6k次。苹方字体是苹果系统上的黑体,挺好看的。注重颜值的网站都会使用,例如知乎:font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, W..._ubuntu pingfang

html表单常见操作汇总_html表单的处理程序有那些-程序员宅基地

文章浏览阅读159次。表单表单概述表单标签表单域按钮控件demo表单标签表单标签基本语法结构<form action="处理数据程序的url地址“ method=”get|post“ name="表单名称”></form><!--action,当提交表单时,向何处发送表单中的数据,地址可以是相对地址也可以是绝对地址--><!--method将表单中的数据传送给服务器处理,get方式直接显示在url地址中,数据可以被缓存,且长度有限制;而post方式数据隐藏传输,_html表单的处理程序有那些

PHP设置谷歌验证器(Google Authenticator)实现操作二步验证_php otp 验证器-程序员宅基地

文章浏览阅读1.2k次。使用说明:开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码。实现Google Authenticator功能需要服务器端和客户端的支持。服务器端负责密钥的生成、验证一次性密码是否正确。客户端记录密钥后生成一次性密码。下载谷歌验证类库文件放到项目合适位置(我这边放在项目Vender下面)https://github.com/PHPGangsta/GoogleAuthenticatorPHP代码示例://引入谷_php otp 验证器

【Python】matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距-程序员宅基地

文章浏览阅读4.3k次,点赞5次,收藏11次。matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距

docker — 容器存储_docker 保存容器-程序员宅基地

文章浏览阅读2.2k次。①Storage driver 处理各镜像层及容器层的处理细节,实现了多层数据的堆叠,为用户 提供了多层数据合并后的统一视图②所有 Storage driver 都使用可堆叠图像层和写时复制(CoW)策略③docker info 命令可查看当系统上的 storage driver主要用于测试目的,不建议用于生成环境。_docker 保存容器

随便推点

网络拓扑结构_网络拓扑csdn-程序员宅基地

文章浏览阅读834次,点赞27次,收藏13次。网络拓扑结构是指计算机网络中各组件(如计算机、服务器、打印机、路由器、交换机等设备)及其连接线路在物理布局或逻辑构型上的排列形式。这种布局不仅描述了设备间的实际物理连接方式,也决定了数据在网络中流动的路径和方式。不同的网络拓扑结构影响着网络的性能、可靠性、可扩展性及管理维护的难易程度。_网络拓扑csdn

JS重写Date函数,兼容IOS系统_date.prototype 将所有 ios-程序员宅基地

文章浏览阅读1.8k次,点赞5次,收藏8次。IOS系统Date的坑要创建一个指定时间的new Date对象时,通常的做法是:new Date("2020-09-21 11:11:00")这行代码在 PC 端和安卓端都是正常的,而在 iOS 端则会提示 Invalid Date 无效日期。在IOS年月日中间的横岗许换成斜杠,也就是new Date("2020/09/21 11:11:00")通常为了兼容IOS的这个坑,需要做一些额外的特殊处理,笔者在开发的时候经常会忘了兼容IOS系统。所以就想试着重写Date函数,一劳永逸,避免每次ne_date.prototype 将所有 ios

如何将EXCEL表导入plsql数据库中-程序员宅基地

文章浏览阅读5.3k次。方法一:用PLSQL Developer工具。 1 在PLSQL Developer的sql window里输入select * from test for update; 2 按F8执行 3 打开锁, 再按一下加号. 鼠标点到第一列的列头,使全列成选中状态,然后粘贴,最后commit提交即可。(前提..._excel导入pl/sql

Git常用命令速查手册-程序员宅基地

文章浏览阅读83次。Git常用命令速查手册1、初始化仓库git init2、将文件添加到仓库git add 文件名 # 将工作区的某个文件添加到暂存区 git add -u # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,不处理untracked的文件git add -A # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,包括untracked的文件...

分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120-程序员宅基地

文章浏览阅读202次。分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120

【C++缺省函数】 空类默认产生的6个类成员函数_空类默认产生哪些类成员函数-程序员宅基地

文章浏览阅读1.8k次。版权声明:转载请注明出处 http://blog.csdn.net/irean_lau。目录(?)[+]1、缺省构造函数。2、缺省拷贝构造函数。3、 缺省析构函数。4、缺省赋值运算符。5、缺省取址运算符。6、 缺省取址运算符 const。[cpp] view plain copy_空类默认产生哪些类成员函数

推荐文章

热门文章

相关标签