美文网首页Mysql
Mysql命令行tips

Mysql命令行tips

作者: 君子世无双 | 来源:发表于2018-05-05 23:26 被阅读10次

作为一名 command line爱好者分享以下几点tips

  1. 在~/.my.cnf中配置如下参数可实现免输入账号密码直接进入数据库
[client]
host=localhost
user=root
password=

进入终端输入mysql

xxx➜~(master)» mysql                                                                                                               [23:34:53]
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.1.9-MariaDB Homebrew

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
  1. 利用别名机制省略use database;
  • vi ~/.zshrc 或者~/.bashrc
  • add
alias xxxdb='mysql xxx'
  • input
source ~/.zshrc 或者 source ~/.bashrc

然后在shell上直接输入xxxdb就可以进入当前选择的数据库

xxx➜~(master)» in4db                                       [17:47:47]
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.1.9-MariaDB Homebrew

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [in4]>
  1. mysql常用命令
    上/下键:调出上一个/下一个输入的命令
    crtl+A:把光标移到输入行的开头
    crtl+E:把光标移到输入航的末尾
    crtl+K:删除从光标位置到输入行末尾的内容
    crtl+l:清屏
  2. 对于常用的查询可以写成sql脚本在命令行运行
    如:mysql db < xxx.sql
    默认情况下输出内容以制表符分隔,使用-t参数可以格式化输出。
    如:mysql -t db < xxx.sql
    如果想把输出结果保存起来,可以重定向至一个文件
    如:mysql -t db < xxx.sql > xxx.out
    如果你已经运行了mysql,可以通过source来运行sql
    如:surce xxx.sql

相关文章

网友评论

    本文标题:Mysql命令行tips

    本文链接:https://www.haomeiwen.com/subject/athyrftx.html