Here's a simpler example that reproduces your problem:
for el in foo bar
do
echo "$el"
done | head -n 1
echo "This is blank: $el"
This happens because the for loop and your mysql statement are not connected in any way. You have to get the data from your loop/pipeline to mysql.
The simplest way of doing this might be a while read loop:
for el in foo bar
do
echo "$el"
done | head -n 1 | while read -r line
do
echo "This is not blank: $line"
done
In your example, this would be:
#!/bin/bash
N=1
ARRAY=( adssa asdsa fdgfd vcbxcxv )
for el in "${ARRAY[@]}"
do echo $el
done | shuf | head -$N | while read -r line
do
mysql -u root -pPass somebase << EOF
INSERT INTO sometable (name) VALUES ('$line');
SELECT * FROM site_user;
EOF
done
The simpler way would be:
#!/bin/bash
n=1
array=( adssa asdsa fdgfd vcbxcxv )
printf "INSERT INTO sometable (name) VALUES ('%s');\n" "${array[@]}" | \
shuf | head -n $n | mysql -u root -pPass somebase