Solved

Store MySQL result in a variable

Posted on 2013-06-03
1
506 Views
Last Modified: 2013-06-03
How would I store the MySQL code below into a variable?

    mysql --host=localhost --user=root --password=admin table <<EOF 2 >> logfile.log
    insert into video (title, description, url_video, upload_date) 
    values('testing','default_description','$filename', '$date_field');
    EOF

Open in new window


I want the script to log MySQL errors to the logfile and need to result of the query to be stored as a variable so it can be used a few times later in the script.
0
Comment
Question by:ipconfig610
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
VAR=$(
mysql --host=localhost --user=root --password=admin table <<EOF 2 >> logfile.log
insert into video (title, description, url_video, upload_date)
values('testing','default_description','$filename', '$date_field');
EOF
)

echo "$VAR"
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now