Shell – MySQL Query

[codesyntax lang=”bash” lines=”no” container=”pre” tab_width=”4″]

#!/bin/bash

# configs
host='localhost';
user='kim';
pass='xxxxxx';
database='test_database';

# select from database
query=`mysql -h$host -u$user -p$pass < tmp;
result=`cut -d' ' -f2- tmp`;
rm -f tmp;

# print result
echo $result;

[/codesyntax]

Posted in Linux | Tagged , | Leave a comment