作为一名 command line爱好者分享以下几点tips
- 在~/.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)]>
- 利用别名机制省略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]>
- mysql常用命令
上/下键:调出上一个/下一个输入的命令
crtl+A:把光标移到输入行的开头
crtl+E:把光标移到输入航的末尾
crtl+K:删除从光标位置到输入行末尾的内容
crtl+l:清屏 - 对于常用的查询可以写成sql脚本在命令行运行
如:mysql db < xxx.sql
默认情况下输出内容以制表符分隔,使用-t参数可以格式化输出。
如:mysql -t db < xxx.sql
如果想把输出结果保存起来,可以重定向至一个文件
如:mysql -t db < xxx.sql > xxx.out
如果你已经运行了mysql,可以通过source来运行sql
如:surce xxx.sql
网友评论