zoukankan      html  css  js  c++  java
  • mysql-shell的安装和使用

    mysql-shell是一个高级的mysql命令行工具、它直接两种模式(交互式&批处理式)三种语言(javascriptpythonsql)

    1、下载地址

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

    2、安装 安装方法就比较简单了,下载一个linux-general版本的解压就行

    mysql-shell-1.0.8-rc-linux-glibc2.12-x86-64bit.tar.gz  -C /usr/local/
    ln -s /usr/local/mysql-shell-1.0.8-rc-linux-glibc2.12-x86-64bit /usr/local/mysqlsh
    export PATH=/usr/local/mysqlsh/bin/:$PATH

    3、通过mysql-shell连接到mysql-server

    mysqlsh 'appuser'@'127.0.0.1':3306
    Creating a Session to 'appuser@127.0.0.1:3306'
    Enter password: 
    Classic Session successfully established. No default schema selected.
    Welcome to MySQL Shell 1.0.8-rc
    
    Copyright (c) 2016, 2017, 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, type 'quit' or 'q' to exit.
    
    Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.
    mysql-js> 

     第每连接都要输入密码、就是不喜欢、好在可以直接指定它

    mysqlsh 'appuser'@'127.0.0.1':3306 --password=123456
    mysqlx: [Warning] Using a password on the command line interface can be insecure.
    Creating a Session to 'appuser@127.0.0.1:3306'
    Classic Session successfully established. No default schema selected.
    Welcome to MySQL Shell 1.0.8-rc
    
    Copyright (c) 2016, 2017, 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, type 'quit' or 'q' to exit.
    
    Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.
    mysql-js> 

    除了这个之处还可以在连接字符串中指定数据库的名字,类似于use dbname;的效果

    mysqlsh 'appuser'@'127.0.0.1':3306/tempdb --password=123456
    mysqlx: [Warning] Using a password on the command line interface can be insecure.
    Creating a Session to 'appuser@127.0.0.1:3306/tempdb'
    Classic Session successfully established. Default schema set to `tempdb`.
    Welcome to MySQL Shell 1.0.8-rc
    
    Copyright (c) 2016, 2017, 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, type 'quit' or 'q' to exit.
    
    Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.
    mysql-js> 

     把密码也加到连接字符串中去

    mysqlsh 'appuser':'123456'@'127.0.0.1':3306/tempdb
    mysqlx: [Warning] Using a password on the command line interface can be insecure.
    Creating a Session to 'appuser@127.0.0.1:3306/tempdb'
    Classic Session successfully established. Default schema set to `tempdb`.
    Welcome to MySQL Shell 1.0.8-rc
    
    Copyright (c) 2016, 2017, 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, type 'quit' or 'q' to exit.
    
    Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.
    mysql-js> 

    4、连接字符串的能用格式

    mysqlsh [dbuser[:[dbpassword]]@]host[:port][/schema]

    5、应用举例

    假设我要执行如下的select 语句、在mysqlsh中我要怎么做呢?

    mysql -uroot -e"select * from tempdb.student" -vt
    --------------
    select * from tempdb.student
    --------------
    
    +------+
    | x    |
    +------+
    |    1 |
    |    2 |
    +------+

    在mysqlsh中要用如下的方式执行

    mysqlsh  --uri 'appuser':'123456'@'127.0.0.1':33060
    mysqlx: [Warning] Using a password on the command line interface can be insecure.
    Creating a Session to 'appuser@127.0.0.1:33060'
    Node Session successfully established. No default schema selected.
    Welcome to MySQL Shell 1.0.8-rc
    
    Copyright (c) 2016, 2017, 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, type 'quit' or 'q' to exit.
    
    Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.
    mysql-js> use tempdb
    Schema `tempdb` accessible through db.
    mysql-js> db.student.select()
    +---+
    | x |
    +---+
    | 1 |
    | 2 |
    +---+

    总结:

      就目前的情况来说mysqlsh是一个数据库初学者的工具(会javascript,python不太精通SQL),像资深的DBA应该还是用不太着的。

      我个人感觉mysqlsh对一个dba来说并没有mysql这个客户端工具来的方便。

    ----

  • 相关阅读:
    [ jquery 选择器 :nth-last-child ] 选取属于其父元素的不限类型的第 n 个子元素的所有元素,从最后一个子元素开始计数
    [ jquery 选择器 :nth-child ] 选取匹配其父元素下的第N个子或奇偶元素
    [ jquery 选择器 :first :first-child ] 实例分析: :first :first-child 之间在元素选取方面的区别
    [ jquery 位置选择器 :first-child :last-child ] 强化说明:选取属于其父元素和所有兄弟元素中子元素集合中处于第一个(最后一个)位置上符合条件的元素
    [ jquery 位置选择器 :first :last ] 强化说明:获取匹配的第一个(最后第一个)元素
    [ jquery 过滤器 is(expr | jqObj | ele | function) ] 此方法用于在选择器的基础之上根据选择器 DOM元素或 jQuery 对象来检测匹配元素集合
    PAT 甲级 1009 Product of Polynomials
    PAT 甲级 1003 Emergency DFS
    PAT 甲级 1002 A+B for Polynomials
    PAT 甲级 1001 A+B Format
  • 原文地址:https://www.cnblogs.com/JiangLe/p/6625901.html
Copyright © 2011-2022 走看看