初识mycli
今天在寻求MYSQL脚本在自动化测试中的运用方法时,被推荐了一款命令行神器mycli-MySQL的命令行客户端
安装
安装mycli之前需要安装依赖
yum install python-pip python-devel
但因为在自己的机子上已经安装了Python,所以安装mycli就很简单了
pip install mycli
使用pip安装服务器在国外的python库时,下载可能需要很长时间,可以试试使用清华镜像源
pip install mycli -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
等待安装结束就好了
连接数据库
和连接MySQL一样,输入
net start mysql
然后连接数据库
mycli -u用户名 -p密码
连接远程MySQL数据库
mycli -h数据库地址 -P端口 -u用户名 -p密码
连接成功后就可以试试输入SQL命令了
mycli使用
$ 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.
支持自动补全和语法高亮