原标题:MySQL Shell:01 从入门到蒙圈

春节马上到了,小伙伴们感受到氛围已经纷纷开溜。(没氛围?华仔的恭喜发财可以让你马上感受下)

中国人过年要有仪式感,包饺子,贴春联,放鞭炮、换红裤衩、烫头等,当然还要发篇公众号。

今天测试的对象是很早就听过但没用过的 MySQLShell那么就看看到底好不好用吧。

可别像这样

过节了对技术不感兴趣没关系,我也准备好了一些出行小知识:

火车上的屎真抛铁轨上了吗?这是我春运路上的终极困惑

什么是MySQLShell

MySQLShell是Oracle官方提供的一个交互式工具,用于开发和管理MySQL的服务器。支持Java、SQL、Python...不,是 木兰接口。

可使用它来执行数据查询、更新以及各种管理操作。

作为Oracle官方未来核心产品:MySQL-Innodb-Cluster 3个亲儿子的中的一个,更可见它受重视的程度。

文档地址:

https://dev.mysql.com/doc/mysql-shell/8.0/en/

开始使用 My SQL Shell

下载地址:

https://dev.mysql.com/downloads/shell/

这里我们下载配套MySQL8的最新版本

直接就可以安装,基本不需要依赖包。

只要mysql命令改成mysqlsh 就可以用了,其他参数不变。

自定义提示符

安装好后,首先做个蛋疼的测试热下身。

和MongoDB一样,MySQL Shell可以用通过prompt来定义自己的提示符。

不同操作系统下,默认命令行提示符配置文件位置不同:

Oracle Linux 7 RPM:

/usr/share/mysqlsh/prompt/

微软Windows:

C:Program FilesMySQLMySQL Shell 8.0sharemysqlshprompt

在Linux 7安装中默认使用这个模板

/usr/share/mysqlsh/prompt/prompt_256.json

官方贴心的提供了很多模板可供使用:

[root@caihao ~] # cd /usr/share/mysqlsh/prompt/

[root@caihao prompt] # ls -l

total 48

-rw-r --r-- 1 root root 1245 Dec 17 03:13 prompt_16.json

-rw-r --r-- 1 root root 1622 Dec 17 03:13 prompt_256inv.json

-rw-r --r-- 1 root root 2137 Dec 17 03:13 prompt_256.json

-rw-r --r-- 1 root root 2179 Dec 17 03:13 prompt_256pl+aw.json

-rw-r --r-- 1 root root 1921 Dec 17 03:13 prompt_256pl.json

-rw-r --r-- 1 root root 183 Dec 17 03:13 prompt_classic.json

-rw-r --r-- 1 root root 2172 Dec 17 03:13 prompt_dbl_256.json

-rw-r --r-- 1 root root 2250 Dec 17 03:13 prompt_dbl_256pl+aw.json

-rw-r --r-- 1 root root 1992 Dec 17 03:13 prompt_dbl_256pl.json

-rw-r --r-- 1 root root 1205 Dec 17 03:13 prompt_nocolor.json

-rw-r --r-- 1 root root 6197 Dec 17 03:13 README.prompt

有2种方式可以切换到其他模板:

exportMYSQLSH_PROMPT_THEME= /usr/share/mysqlsh/prompt/prompt_256pl+aw.json

或者

cp prompt_256pl+aw.json ~ /.mysqlsh/prompt.json

这里我们做个自定义配置,默认提示符是这样的:

下面通过修改配置,在提示符中加入连接数据库的版本信息:

vim/usr/share/mysqlsh/prompt/prompt_256.json

添加如下代码:

{

"separator": "",

"text": "%sysvar:version%",

"bg": 250,

"fg": 166

},

检验下效果,已经可以看到这个数据库是5.7.29版本。

我之前已经在容器中搞了4个版本的数据库,分别对应3305 3306 3307 3308 这4个端口。

( 具体方法可以参考我之前的文章: 在Docker中玩转MySQL )

[root@caihao ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

d8d14c9ddecb mysql/mysql- server: 8.0"/entrypoint.sh my..."2hours ago Up About an hour(healthy) 0.0.0.0: 3308-> 3306/tcp, 0.0.0.0: 33080-> 33060/tcp mysql -8.0

b48d63358964 mysql/mysql- server: 5.7"/entrypoint.sh my..."2hours ago Up About an hour(healthy) 0.0.0.0: 3307-> 3306/tcp, 0.0.0.0: 33070-> 33060/tcp mysql -5.7

9cf7b7541ad0 mysql/mysql- server: 5.6"/entrypoint.sh my..."2hours ago Up About an hour(healthy) 0.0.0.0: 3306-> 3306/tcp, 0.0.0.0: 33060-> 33060/tcp mysql -5.6

c082d308bb96 mysql/mysql- server: 5.5"/entrypoint.sh my..."2hours ago Up About an hour(healthy) 0.0.0.0: 3305-> 3306/tcp, 0.0.0.0: 33050-> 33060/tcp mysql -5.5

[root@caihao ~]#

对应的版本、主机名、端口都可以显示。注意5.7以上还使用了SSL

还可以自定义字体,比如做成这样的。

测试3种功能模式

MySQL Shell不仅是一个增强版mysql客户端工具,还提供Java和Python脚本功能。

3种模式的切换:

py

sql

js

SQL操作已经可以做自动补全

Python操作,可以直接执行自己写的py程序:

JS方式可以执行json文档操作,这里先建立一个Collection

然后在Collection中插入数据

查询json数据,最后删除测试表

JS也可以进行各种数据库管理工作

比如管理Replicaset,这个最近新出的功能配置比较繁琐,以后专门写一篇。

MySQL 8.0.19localhost: 3306+ ssl JS > rs.status;

{

"replicaSet": {

"name": "testReplicaset",

"primary": "test77:3306",

"status": "AVAILABLE",

"statusText": "All instances available.",

"topology": {

"test77:3306": {

"address": "test77:3306",

"instanceRole": "PRIMARY",

"mode": "R/W",

"status": "ONLINE"

},

"test78:3306": {

"address": "test78:3306",

"instanceRole": "SECONDARY",

"mode": "R/O",

"replication": {

"applierStatus": "APPLIED_ALL",

"applierThreadState": "Slave has read all relay log; waiting for more updates",

"receiverStatus": "ON",

"receiverThreadState": "Waiting for master to send event",

"replicationLag": null

},

"status": "ONLINE"

}

},

"type": "ASYNC"

}

}

升级检查功能

Oracle在MySQL Shell 中偷偷的集成了3个小工具,其中一个是升级检查功能:

util.checkForServerUpgrade;

通过它可以验证MySQL服务器实例是否已准备好进行升级。

但是要注意以下2点:

只支持检查MySQL 5.7之后版本的MySQL

仅支持GA版本之间的升级。不支持从非GA版本的MySQL 5.7或8.0升级

具体文档:

https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-upgrade.html

我们在5.7的库上测试下:

MySQL 5.7. 29localhost: 3307ssl JS > util.checkForServerUpgrade;

The MySQL server at localhost: 3307, version 5.7. 29- MySQL Community Server

(GPL), will now be checked forcompatibility issues forupgrade toMySQL

8.0. 19...

1) Usage ofold temporal type

No issues found

2) Usage ofdb objects withnames conflicting withnew reserved keywords

No issues found

3) Usage ofutf8mb3 charset

No issues found

4) Table names inthe mysql schema conflicting withnew tables in8.0

No issues found

5) Partitioned tables using engines withnon native partitioning

No issues found

6) Foreign key constraint names longer than 64characters

No issues found

7) Usage ofobsolete MAXDB sql_mode flag

No issues found

8) Usage ofobsolete sql_mode flags

No issues found

9) ENUM/ SETcolumn definitions containing elements longer than 255characters

No issues found

10) Usage ofpartitioned tables inshared tablespaces

No issues found

11) Circular directory references intablespace data filepaths

No issues found

12) Usage ofremoved functions

No issues found

13) Usage ofremoved GROUP BY ASC/DESC syntax

No issues found

14) Removed system variables forerror logging tothe system log configuration

Torun this check requires full path toMySQL server configuration filetobe specified at 'configPath'key ofoptions dictionary

More information:

https: //dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html#mysqld-8-0-13-logging

15) Removed system variables

Torun this check requires full path toMySQL server configuration filetobe specified at 'configPath'key ofoptions dictionary

More information:

https: //dev.mysql.com/doc/refman/8.0/en/added-deprecated-removed.html#optvars-removed

16) System variables withnew defaultvalues

Torun this check requires full path toMySQL server configuration filetobe specified at 'configPath'key ofoptions dictionary

More information:

https: //mysqlserverteam.com/new-defaults-in-mysql-8-0/

17) Zero Date, Datetime, andTimestamp values

No issues found

18) Schema inconsistencies resulting from fileremoval orcorruption

No issues found

19) Tables recognized by InnoDB that belong toa different engine

No issues found

20) Issues reported by 'check table x for upgrade'command

No issues found

21) New defaultauthentication plugin considerations

Warning: The new defaultauthentication plugin 'caching_sha2_password'offers

more secure password hashing than previously used 'mysql_native_password'

( andconsequent improved client connection authentication). However, it also

has compatibility implications that may affect existing MySQL installations.

Ifyour MySQL installation must serve pre- 8.0clients andyou encounter

compatibility issues after upgrading, the simplest way toaddress those

issues istoreconfigure the server torevert tothe previous default

authentication plugin (mysql_native_password). Forexample, use these lines

inthe server option file:

[mysqld]

default_authentication_plugin=mysql_native_password

However, the setting should be viewed astemporary, notasa long term or

permanent solution, because it causes new accounts created withthe setting

ineffect toforego the improved authentication security.

Ifyou are using replication please take time tounderstand how the

authentication plugin changes may impact you.

More information:

https: //dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatibility-issues

https: //dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-replication

Errors: 0

Warnings: 1

Notices: 0

No fatal errors were found that would prevent an upgrade, but some potential issues were detected. Please ensure that the reported issues are notsignificant before upgrading.

MySQL 5.7. 29localhost: 3307ssl JS >

但是在5.6版本,就会提示不支持

年前基本就不做更新了,路上无聊,走过路过的同学可以看看下面的历史文章。

祝你有个愉快放松的春节。

GitHub都在用的高可用工具Orch:

Percona 全力打造的监控平台 PMM:

责任编辑:

shell mysql版本_MySQL Shell:01 从入门到蒙圈相关推荐

  1. shell mysql版本_mysql版本5.5.x升级到5.6.x步骤分享

    大概步骤是: 把配置文件添加:skip-grant-tables参数,把basedir升级成新版本,启动mysql,执行命令:mysql_upgrade升级一下字典信息,然后flush privile ...

  2. mysqlclient==1.3.7对应mysql版本_MySQL 5.7.30 的安装/升级(所有可能的坑都在这里)...

    由于之前电脑上安装的MySQL版本是比较老的了,大概是5.1的版本,不支持JSON字段功能.而最新开发部门开发的的编辑器产品,使用到了JSON字段的功能. 因此需要升级MySQL版本,升级的目标版本是 ...

  3. lnmp 查看mysql版本_MySQL数据库之Lnmp环境中php-mysql版本问题

    本文主要向大家介绍了MySQL数据库之Lnmp环境中php-mysql版本问题 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 操作系统:CentOS release 6.7 ( ...

  4. linux shell mysql备份_linux shell 备份mysql 数据库

    #!/bin/bash host="目标ip" id="用户名" pwd="密码" dbs=$(echo "show databa ...

  5. mysql中的shell脚本命令_shell脚本中mysql命令

    展开全部 本文介绍 MySQL 8.0 shell 子模块 Util 的两个导入特性 importTable/import_table(JS和python 版本的命名差e68a84e8a2ad6261 ...

  6. centos shell mysql数据库备份_CentOS6.5下通过Shell创建、备份、还原MySQL数据库

    CentOS6.5下通过Shell创建.备份.还原MySQL数据库 创建数据库: mysql -uroot -p123456 -e "CREATE DATABASE IF NOT EXIST ...

  7. JB的Shell之旅-30分钟带你入门

    前言 写这篇文章的目的很简单,因为爱并恨过: 前段时间要改个安卓产品的脚本,惊奇发现理论是用shell,虽然实现的功能不复杂,但如果对没了解过shell或懂皮毛的同学,改起来是相当痛苦(如jb),调试 ...

  8. 【shell脚本编程大全-笔录01】

    环境变量 全局.局部环境变量 ​ 用户变量(局部变量):修改的设置只对某个用户的路径或执行起作用: ​ 系统变量(全局变量):影响范围是整个系统 : 系统环境变量基本上都是使用全大写字母,以区别于普通 ...

  9. shell mysql awk_shell mysql 处理数据小结

    shell mysql 处理数据小结,shell中子进行变量的传递看了好久.. 学习一下另一种思维方式 [root@ccsafe cc]# cat productinfo.sh #!/bin/bash ...

最新文章

  1. 给你一个亿的keys,Redis如何统计?
  2. 新书上市 | NetLogo开荒之作!
  3. 数据库-数据类型及主键外键
  4. AD在Windows Server 2003中的更新(中)
  5. 【招聘(北京)】北森测评招聘 .NET 架构师、高级工程师
  6. 第六十四期:聊聊原子变量、锁、内存屏障那点事
  7. 百度SEO Typecho仿Win95怀旧主题
  8. go socket编程(详细)
  9. 沫沫金::struts下载文档[解决方案]
  10. 3809. 修改数组——AcWing题库
  11. 手把手教你用python写游戏
  12. 一句话说明sync, fsync, fdatasync的区别
  13. 项目中git的运用及命令明细
  14. 硬件防火墙 与软件防火墙
  15. 你知道map,filter,sort,reduct,every, some 的用法吗?
  16. html360搜索框代码,HTML 代码标签
  17. 怎么调整计算机显示屏,电脑显示器画面怎么调整
  18. 再次慨叹生命的脆弱,我辈当惜之
  19. 中国嵌入式打印机市场趋势报告、技术动态创新及市场预测
  20. Linux系列之查看进程线程的方法

热门文章

  1. pandas相关性能以及工作总结
  2. 嗖嗖移动大厅之卡号类
  3. Oracle总结(一):Oracle执行计划
  4. 13、数码相框编写程序之支持中文和课后作业
  5. 食用甜玉米:增进健康,老少皆宜
  6. 企业云上安全办公,就用华为云桌面
  7. 计算机维修的专业小结,计算机维护专业自我鉴定范文(精选5篇)
  8. Python 导入模块
  9. 游侠客php,少年游侠客
  10. Windows10任务栏的搜索框是否可以替代Everything这款搜索软件