mysqldump:找不到表:“|”

时间:2013-09-21 15:42:06

标签: mysql expect

我尝试执行exp文件:

#!/usr/bin/expect

# mysql credentials and connection data
current_db_name='webui_dev'
new_db_name='db_2013'
db_host='localhost'
db_user='root'
db_pass=''


# using a here-document to pass commands to expect. 
# (the commands could be stored in a file as well)
expect <<EOF
  log_user 0
  spawn mysqldump -h "$db_host" -u "$db_user" -p "$current_db_name" | mysql -h "$db_host" -u "$db_user" -p "$new_db_name"
  expect "password:"
  send "$db_pass\r"
  log_user 1
  expect eof
EOF

我使用-f标志执行if,并收到错误:mysqldump: Couldn't find table: "|"

如果我尝试这种方法

exp_internal 1
  spawn sh -c  "mysqldump -h \"$db_host\" -u \"$db_user\" -p \"$current_db_name\" | mysql -h \"$db_host\" -u \"$db_user\" -p \"$new_db_name\" "

我得到了一个输出

expect: option requires an argument -- f
usage: expect [-div] [-c cmds] [[-f] cmdfile] [args]
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {81914}

expect: does "" (spawn_id exp7) match glob pattern "password:"? no

expect: does "Enter password: " (spawn_id exp7) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "Enter password:"
send: sending "\r" to { exp7 }

Enter password: expect: timed out

3 个答案:

答案 0 :(得分:3)

当Johannes说使用shell时,他的意思是:

  spawn sh -c "mysqldump -h \"$db_host\" -u \"$db_user\" -p \"$current_db_name\" | mysql -h \"$db_host\" -u \"$db_user\" -p \"$new_db_name\""

答案 1 :(得分:1)

mysqldump命令获取您给定的参数,在数据库名称之后,它需要表名称

所以假设 | 是一个表名

mysqldump [options] db_name [tbl_name ...]

更新回答

为了转储一组一个或多个表,

shell> mysqldump [options] db_name [tbl_name ...]

一组一个或多个完整数据库

shell> mysqldump [options] --databases db_name ...

或整个MySQL服务器 - 如下所示:

shell> mysqldump [options] --all-databases

答案 2 :(得分:0)

在我的 Mac 上,我使用了这个命令:

mysqldump -u root -p [database_name] > /Users/rgavila/Documents/_WSCenter/Backup-Jul-5-2021.sql

只需包含一个 V 形 (>) 即可将文件推送到我想要的位置。

屏幕开始工作时就安静了。