一、概述
MyCli 是一个 MySQL 命令行工具,支持自动补全和语法高亮。也可用于 MariaDB 和 Percona。
mycli 使用 prompt_toolkit 编写。
- 当你输入 SQL 关键字,数据库的表格和列时,自动补全。
- 语法高亮使用 Pygments.
- 智能补全(默认启用),会提示文本感应的(context-sensitive)补全。
- SELECT * FROM只显示表格名称
- SELECT * FROM users WHERE只显示列名称。
- 配置文件在第一次启动时,自动创建在 ~/.myclirc
- 漂亮的打印表格数据。
二、安装部署
2.1 安装依赖软件python-pip
1、安装epel yum源及安装python-devel
sudo yum -y install epel-release yum install python-devel sudo yum -y install python-pip sudo yum clean all
2.2 安装mycli
pip install mycli
三、使用展示
3.1 参数简易说明
mycli的使用方法跟mysql命令很类似
[root@181 ~]# mycli --help Usage: mycli [OPTIONS] [DATABASE] ? A MySQL terminal client with auto-completion and syntax highlighting. ? Examples: - mycli my_database - mycli -u my_user -h my_host.com my_database - mycli mysql://my_user@my_host.com:3306/my_database ? Options: -h, --host TEXT Host address of the database. -P, --port INTEGER Port number to use for connection. Honors $MYSQL_TCP_PORT. -u, --user TEXT User name to connect to the database. -S, --socket TEXT The socket file to use for connection. -p, --password TEXT Password to connect to the database. --pass TEXT Password to connect to the database. --ssh-user TEXT User name to connect to ssh server. --ssh-host TEXT Host name to connect to ssh server. --ssh-port INTEGER Port to connect to ssh server. --ssh-password TEXT Password to connect to ssh server. --ssh-key-filename TEXT Private key filename (identify file) for the ssh connection. --ssl-ca PATH CA file in PEM format. --ssl-capath TEXT CA directory. --ssl-cert PATH X509 cert in PEM format. --ssl-key PATH X509 key in PEM format. --ssl-cipher TEXT SSL cipher to use. --ssl-verify-server-cert Verify server's "Common Name" in its cert against hostname used when connecting. This option is disabled by default. -V, --version Output mycli's version. -v, --verbose Verbose output. -D, --database TEXT Database to use. -d, --dsn TEXT Use DSN configured into the [alias_dsn] section of myclirc file. --list-dsn list of DSN configured into the [alias_dsn] section of myclirc file. -R, --prompt TEXT Prompt format (Default: "\t \u@\h:\d> "). -l, --logfile FILENAME Log every query and its results to a file. --defaults-group-suffix TEXT Read MySQL config groups with the specified suffix. --defaults-file PATH Only read MySQL options from the given file. --myclirc PATH Location of myclirc file. --auto-vertical-output Automatically switch to vertical output mode if the result is wider than the terminal width. -t, --table Display batch output in table format. --csv Display batch output in CSV format. --warn / --no-warn Warn before running a destructive query. --local-infile BOOLEAN Enable/disable LOAD DATA LOCAL INFILE. --login-path TEXT Read this path from the login file. -e, --execute TEXT Execute command and quit. --help Show this message and exit.
常用参数说明:
- -h:数据库主机的ip地址
- -P:连接数据库端口
- -u:连接数据库用户
- -p(小写):连接数据库的密码
- -D:连接使用的数据库
- -e:执行的命令
3.2 示例展示
1、查看数据库
2、查询表
四、小结
- 这个小工具能极大便利DBA和运维人员的数据库操作工作。
- 安装简单,无需配置。
觉得有用的朋友多帮忙转发哦!后面会分享精彩的内容,感兴趣的朋友可以关注下~
本文暂时没有评论,来添加一个吧(●'◡'●)