如何将shell脚本内容写入mysql

2025-04-19 18:27:57

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/expectset timeout 2#登陆数据库spawn mysql -uroot -p123456send "\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
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢