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

智能推荐

攻防世界_难度8_happy_puzzle_攻防世界困难模式攻略图文-程序员宅基地

文章浏览阅读645次。这个肯定是末尾的IDAT了,因为IDAT必须要满了才会开始一下个IDAT,这个明显就是末尾的IDAT了。,对应下面的create_head()代码。,对应下面的create_tail()代码。不要考虑爆破,我已经试了一下,太多情况了。题目来源:UNCTF。_攻防世界困难模式攻略图文

达梦数据库的导出(备份)、导入_达梦数据库导入导出-程序员宅基地

文章浏览阅读2.9k次,点赞3次,收藏10次。偶尔会用到,记录、分享。1. 数据库导出1.1 切换到dmdba用户su - dmdba1.2 进入达梦数据库安装路径的bin目录,执行导库操作  导出语句:./dexp cwy_init/[email protected]:5236 file=cwy_init.dmp log=cwy_init_exp.log 注释:   cwy_init/init_123..._达梦数据库导入导出

js引入kindeditor富文本编辑器的使用_kindeditor.js-程序员宅基地

文章浏览阅读1.9k次。1. 在官网上下载KindEditor文件,可以删掉不需要要到的jsp,asp,asp.net和php文件夹。接着把文件夹放到项目文件目录下。2. 修改html文件,在页面引入js文件:<script type="text/javascript" src="./kindeditor/kindeditor-all.js"></script><script type="text/javascript" src="./kindeditor/lang/zh-CN.js"_kindeditor.js

STM32学习过程记录11——基于STM32G431CBU6硬件SPI+DMA的高效WS2812B控制方法-程序员宅基地

文章浏览阅读2.3k次,点赞6次,收藏14次。SPI的详情简介不必赘述。假设我们通过SPI发送0xAA,我们的数据线就会变为10101010,通过修改不同的内容,即可修改SPI中0和1的持续时间。比如0xF0即为前半周期为高电平,后半周期为低电平的状态。在SPI的通信模式中,CPHA配置会影响该实验,下图展示了不同采样位置的SPI时序图[1]。CPOL = 0,CPHA = 1:CLK空闲状态 = 低电平,数据在下降沿采样,并在上升沿移出CPOL = 0,CPHA = 0:CLK空闲状态 = 低电平,数据在上升沿采样,并在下降沿移出。_stm32g431cbu6

计算机网络-数据链路层_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输-程序员宅基地

文章浏览阅读1.2k次,点赞2次,收藏8次。数据链路层习题自测问题1.数据链路(即逻辑链路)与链路(即物理链路)有何区别?“电路接通了”与”数据链路接通了”的区别何在?2.数据链路层中的链路控制包括哪些功能?试讨论数据链路层做成可靠的链路层有哪些优点和缺点。3.网络适配器的作用是什么?网络适配器工作在哪一层?4.数据链路层的三个基本问题(帧定界、透明传输和差错检测)为什么都必须加以解决?5.如果在数据链路层不进行帧定界,会发生什么问题?6.PPP协议的主要特点是什么?为什么PPP不使用帧的编号?PPP适用于什么情况?为什么PPP协议不_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输

软件测试工程师移民加拿大_无证移民,未受过软件工程师的教育(第1部分)-程序员宅基地

文章浏览阅读587次。软件测试工程师移民加拿大 无证移民,未受过软件工程师的教育(第1部分) (Undocumented Immigrant With No Education to Software Engineer(Part 1))Before I start, I want you to please bear with me on the way I write, I have very little gen...

随便推点

Thinkpad X250 secure boot failed 启动失败问题解决_安装完系统提示secureboot failure-程序员宅基地

文章浏览阅读304次。Thinkpad X250笔记本电脑,装的是FreeBSD,进入BIOS修改虚拟化配置(其后可能是误设置了安全开机),保存退出后系统无法启动,显示:secure boot failed ,把自己惊出一身冷汗,因为这台笔记本刚好还没开始做备份.....根据错误提示,到bios里面去找相关配置,在Security里面找到了Secure Boot选项,发现果然被设置为Enabled,将其修改为Disabled ,再开机,终于正常启动了。_安装完系统提示secureboot failure

C++如何做字符串分割(5种方法)_c++ 字符串分割-程序员宅基地

文章浏览阅读10w+次,点赞93次,收藏352次。1、用strtok函数进行字符串分割原型: char *strtok(char *str, const char *delim);功能:分解字符串为一组字符串。参数说明:str为要分解的字符串,delim为分隔符字符串。返回值:从str开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。其它:strtok函数线程不安全,可以使用strtok_r替代。示例://借助strtok实现split#include <string.h>#include <stdio.h&_c++ 字符串分割

2013第四届蓝桥杯 C/C++本科A组 真题答案解析_2013年第四届c a组蓝桥杯省赛真题解答-程序员宅基地

文章浏览阅读2.3k次。1 .高斯日记 大数学家高斯有个好习惯:无论如何都要记日记。他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?高斯出生于:1777年4月30日。在高斯发现的一个重要定理的日记_2013年第四届c a组蓝桥杯省赛真题解答

基于供需算法优化的核极限学习机(KELM)分类算法-程序员宅基地

文章浏览阅读851次,点赞17次,收藏22次。摘要:本文利用供需算法对核极限学习机(KELM)进行优化,并用于分类。

metasploitable2渗透测试_metasploitable2怎么进入-程序员宅基地

文章浏览阅读1.1k次。一、系统弱密码登录1、在kali上执行命令行telnet 192.168.26.1292、Login和password都输入msfadmin3、登录成功,进入系统4、测试如下:二、MySQL弱密码登录:1、在kali上执行mysql –h 192.168.26.129 –u root2、登录成功,进入MySQL系统3、测试效果:三、PostgreSQL弱密码登录1、在Kali上执行psql -h 192.168.26.129 –U post..._metasploitable2怎么进入

Python学习之路:从入门到精通的指南_python人工智能开发从入门到精通pdf-程序员宅基地

文章浏览阅读257次。本文将为初学者提供Python学习的详细指南,从Python的历史、基础语法和数据类型到面向对象编程、模块和库的使用。通过本文,您将能够掌握Python编程的核心概念,为今后的编程学习和实践打下坚实基础。_python人工智能开发从入门到精通pdf

推荐文章

热门文章

相关标签