mysql-shell的安裝和使用


mysql-shell是一個高級的mysql命令行工具、它直接兩種模式(交互式&批處理式)三種語言(javascript\python\sql)

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這個客戶端工具來的方便。

----


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM