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
相关文章:
