网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 生活知识 知识问答

如何将shell脚本内容写入mysql

时间:2026-02-13 13:58:24

1、执行命令“yum install tcl”安装tcl工具;

如何将shell脚本内容写入mysql

2、执行命令“yum install expect -y”安装expect;

如何将shell脚本内容写入mysql

3、执行命令“ cd /home ”进入服务器根目录home;

4、执行命令“touch shell_mysql.exp”创建shell脚本交互式文件

如何将shell脚本内容写入mysql

5、执行命令“vim shell_mysql.exp”编辑shell脚本文件并输入以下内容:

#!/usr/bin/expect  

set timeout 2

#登陆数据库

spawn mysql -uroot -p123456

send "\r"

#创建数据库并设置utf编码

send "create database depart;"

send "\r"

send "use depart;"

send "\r"

send "set names utf8;"

send "\r"

#创建表并设置2个字段

send "create table student( id int(10), name varchar(50) ); "

send "\r"

#插入一条学生信息

send "insert into student values(1,'王熙凤');"

send "\r"

#退出并结束登陆

send "quit"

send "\r"

expect eof

6、执行命令“:wq”保存退出当前文件;

7、执行命令“ chmod -R 777 shell_mysql.exp ”给脚本赋予权限;

如何将shell脚本内容写入mysql

8、执行命令“ ./shell_mysql.exp ”运行shell脚本;

如何将shell脚本内容写入mysql

如何将shell脚本内容写入mysql

9、验证环节:打开桌面客户端Navicat连接数据库能够查看到我们插入的学生信息。至此shell脚本操作mysql数据库的演示已经完成。

如何将shell脚本内容写入mysql

© 2026 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com