mysql source命令如何把日志记录到文件里面
在msyql数据库备份过程中,使用source命令,日志都打印在界面上了,如何让它输入到一个文件里面?
高洛峰2017-04-17 15:26:47
Run in mysql shell before execution
tee output.log
After that, the output of any command you run will be printed in it. output.log is the file you want, with any name and any path
ringa_lee2017-04-17 15:26:47
You can use expect. For example, I often use this import.sh
script:
#!/usr/bin/env expect
if {$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 -p
expect "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
Then, just import a database and log:
import.sh path/to/sqlfile.sql some_database >> import.log