使用Shell脚本将值插入到MySql表中

我是Shell脚本的新手,我正在尝试使用Shell脚本将值插入到mySql数据库中。以下脚本的问题在于该脚本连接到数据库并等待用户提示(不执行插入行)。

我希望脚本连接到数据库并执行插入命令。

Shell脚本:

#!/bin/sh
#The objective of this script is to connect to MySql
mysql -h 127.0.0.1 -P 3306 -u root
use test;
INSERT INTO Animals(Legs,Hands)
VALUES (2,3);

输出:

Jane-MBP:nScript Jane$ ./nmysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.5.5-10.4.8-MariaDB Source distribution

Copyright (c) 2000,2019,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> exit
Bye
./nmysql: line 4: use: command not found
./nmysql: line 5: syntax error near unexpected token `('
./nmysql: line 5: `INSERT INTO Animals(Legs,Hands)'
Jane-MBP:nScript Jane$ 
louislee511 回答:使用Shell脚本将值插入到MySql表中

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3106354.html

大家都在问