mysql source命令如何把日志记录到文件里面
问题描述
mysql source命令如何把日志记录到文件里面
在msyql数据库备份过程中,使用source命令,日志都打印在界面上了,如何让它输入到一个文件里面?
问题解答
回答1:执行前在mysql shell里面运行
tee output.log
之后你运行任何命令输出都会打在里面。output.log就是你要的文件,名字随便,路径随便
回答2:可以使用expect,比如我常用这样的一个import.sh脚本:
#!/usr/bin/env expectif {$argc<2} { send_user 'Usage: $argv0 sql_file database' exit}set sql_file [lindex $argv 0]set database [lindex $argv 1]spawn mysql -u root -pexpect 'password:'send '你的密码r'expect 'mysql>'send 'create database $database CHARACTER SET utf8 COLLATE utf8_general_ci;r'expect 'mysql>'send 'use $database;r'expect 'mysql>'send 'source $sql_file;r'expect 'mysql>'send 'show tables;r'expect 'mysql>'send 'quit;r'expect eof
然后,导入一个数据库并且记录日志就这样就行了:
import.sh path/to/sqlfile.sql some_database >> import.log
相关文章:
1. docker-compose中volumes的问题2. docker安装后出现Cannot connect to the Docker daemon.3. docker网络端口映射,没有方便点的操作方法么?4. nignx - docker内nginx 80端口被占用5. node.js - antdesign怎么集合react-redux对input控件进行初始化赋值6. docker api 开发的端口怎么获取?7. mac里的docker如何命令行开启呢?8. javascript - js如何获取app保存的TOKEN?9. docker - 如何修改运行中容器的配置10. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?

网公网安备