Bash script to insert values in MySQL

后端 未结 5 864
别跟我提以往
别跟我提以往 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:20

    Try this one:

    #!/bin/bash
    inputfile="test.txt"
    cat $inputfile | while read ip mac server; do
        echo "INSERT INTO test (IP,MAC,SERVER) VALUES ('$ip', '$mac', '$server');"
    done | mysql -uroot -ptest test;
    

    This way you streaming the file read as well the mysql comand execution.

提交回复
热议问题