mysql source命令如何把日志记录到文件里面
PHP中文网
PHP中文网 2017-04-17 15:24:47
0
2
678

mysql source命令如何把日志记录到文件里面

在msyql数据库备份过程中,使用source命令,日志都打印在界面上了,如何让它输入到一个文件里面?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
小葫芦

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

左手右手慢动作

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template