I\'m trying to make a bash script that creates a mysql user and database but I can\'t find a way to feed the sql into mysql, I\'m trying with this format:
my
The reason your attempt did not work was because the < expects a file name and you fed it a string. You would have to do something like
echo "YOURQUERYSTRINGHERE">tmpfile
mysql --host=localhost --user=user --password=password dbname
ken's suggestion of
mysql --host=localhost --user=user --password=password -e "QUERY" dbname
can work, but if you try to use bash variables in your query you can fall foul of parameter expansion. eg
QUERY="select * from $MYTABLE WHERE name=\"silly@place.com\";"
mysql --host=localhost --user=user --password=password -e "$QUERY" mydbname
may not do what you expect. One option is use
echo "$QUERY"|mysql --host=localhost --user=user --password=password mydbname
which works if the query string contains appropriate quoting. Another option is the "here" document as suggested by dogbane.