MySQL Insertion Script with Bash Scripting
When attempting to insert values into a MySQL database via a bash script, you may encounter an error regarding column count mismatch. This indicates that your script is attempting to insert values that do not align with the number of columns in the target table.
To resolve this issue, consider modifying your bash script as follows:
#!/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;
In this updated script:
This modified script reads the values from the text file line by line and executes the insert operation for each set of values, accounting for the correct number of columns in the target table.
The above is the detailed content of How to Fix MySQL Column Count Mismatch Errors When Inserting Data with a Bash Script?. For more information, please follow other related articles on the PHP Chinese website!