Use expect command to interact with mysql in linux system

原创 2013年12月02日 10:43:59

The "expect" command is not install in some linux system default , in the ubuntu system , you can simplly tap "sudo apt-get install expect" to install this tool.

And then , if you want to use to in the shell script , the first line maybe like this:

#!/use/bin/expect

It just like bash or sh . check the example below:

$:~/test$ expect
expect1.1> spawn mysql -h localhost -u db_runner -p
spawn mysql -h localhost -u db_runner -p
27022
expect1.2> expect "password:"
Enter password: expect1.3> send "mysqlpassword\r"
expect1.4> expect "mysql>"

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 88
Server version: 5.5.34-0ubuntu0.13.04.1 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> expect1.5> send "show databases;\r"
expect1.6> expect "mysql>"
show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
9 rows in set (0.00 sec)

mysql> expect1.7> send "exit;\r"
expect1.8> expect "mysql>"
exit;
Bye

相关文章推荐

How to Change the Hostname of a Linux System

原文:http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/ Normally we ...

How to read the Linux system name?

How to read the Linux system name?This is really instersting question, the Linux system like Debian ...

user, group, password in Linux system

user: /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin:x:2...

iOS开发中Xcode编译错误 linker command failed with exit code 1 (use -v to see invocation) 的解决办法

clang: error: linker command failed with exit code 1 (use -v to see invocation) 的Xcode错误调试,在iOS开发中算是...
  • Aaidong
  • Aaidong
  • 2015年05月15日 08:54
  • 6328

linker command failed with exit code 1 (use -v to see invocation)问题

cd /Users/kong/Desktop/SearchTest export IPHONEOS_DEPLOYMENT_TARGET=8.1 export PATH="/Applic...
  • klshuo
  • klshuo
  • 2015年12月01日 11:46
  • 420

iOS调试错误 linker command failed with exit code 1 (use -v to see invocation)

linker command failed with exit code 1 (use -v to see invocation)调试错误原因总结 情况1、 linker comma...

linker command failed with exit code 1 (use -v to see invocation)删除sdk或者静态库之后,没清干净,导致路径下还有

linker command failed with exit code 1 (use -v to see invocation)删除sdk或者静态库之后,没清干净,导致路径下还有起因: 哎呦我去,...

编译出现错误:linker command failed with exit code 1 (use -v to see invocation)

今天编译项目的时候,报错,linker command failed with exit code 1 (use -v to see invocation) 总结一下这个可能存在的原因: 1、工程...
  • JWheat
  • JWheat
  • 2017年06月29日 12:16
  • 330

错误: error linker command failed with exit code 1 (use –v to see invocation)

error linker command failed with exit code 1 (use –v to see invocation) , error linker 错误汇总...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Use expect command to interact with mysql in linux system
举报原因:
原因补充:

(最多只允许输入30个字)