Bash script to insert values in MySQL

后端 未结 5 868
别跟我提以往
别跟我提以往 2020-11-30 07:48

I want to make a bash script that connects to my MySQL server and inserts some valuse from a txt file. I have written this down:

#!/bin/bash
echo \"INSERT I         


        
5条回答
  •  渐次进展
    2020-11-30 08:32

    You are trying to insert the value "cat test.txt" as a String in the database in an INSERT statement that requires 3 parameters (IP,MAC and SERVER) so this is why you get this error message.

    You need to read the text file first and extract the IP, MAC and Server values and then use these in the query that would look like this once filled :

    #!/bin/bash
    echo "INSERT INTO test (IP,MAC,SERVER) VALUES ('10.16.54.29', '00:f8:e5:33:22:3f', 'marsara');" | mysql -uroot -ptest test;
    

提交回复
热议问题