Putting mysql column value in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Putting mysql column value in variable
# 1  
Old 05-20-2013
Putting mysql column value in variable

Hello,
i have the following code :

Code:
somevariable=`mysql -u root --password="" databasename -e "select count(column_name) from table_name where id=1 and id_age=2 ; " --skip-column-names -s -N`
			if [[  $somevariable -eq 0 ]] 
			then  ....

It gives the message

Code:
")syntax error: invalid arithmetic operator (error token is "

Could be that i don't have a mysql password and the syntax is wrong in that case?

Thank you!

Last edited by Scrutinizer; 05-20-2013 at 07:15 AM.. Reason: code tags
# 2  
Old 05-30-2013
Is this a carriage return problem? In other words, are you using the code on both Windows and POSIX machines?
The error message is related to bash, not to mysql.
# 3  
Old 06-03-2013
i did it with

somevariable=$(mysql -uroot database -sN -e "select count(id) from some_table where id='$id' ;")

Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking nth column and putting its value in n+1 column using awk

Hello Members, Need your expert opinion how to tackle below. I have an input file that looks like below: USS|AWCC|AFGAW|93|70 USSAA|Roshan TDCA|AFGTD|93|72,79 ALB|Vodafone|ALBVF|355|69 ALGEE|Wataniya (Nedjma)|DZAWT|213|50,550 I like output file in below format: ... (7 Replies)
Discussion started by: umarsatti
7 Replies

2. Shell Programming and Scripting

Update a mysql column via bash script

Hello, I want to check the value of all MySQL columns.(column name is "status") via bash script. If value is "0" at I want to make only single column value to "1" I have many "0" values on mysql database(on "status" column) "0" means it is a draft post. I want to publish a post. I... (2 Replies)
Discussion started by: tara123
2 Replies

3. Shell Programming and Scripting

Need to extract data from Column having variable length column

Hi , I need to extract data from below mentioned data, having no delimiter and havin no fixed column length. For example: Member nbr Ref no date 10000 1000 10202012 200000 2000 11202012 Output: to update DB with memeber nbr on basis of ref no. ... (6 Replies)
Discussion started by: ns64110
6 Replies

4. Shell Programming and Scripting

Text file -> fixed column -> MySQL DB

Hi ! I have searched in the forum, but i'm not able to combine various solution to help me ! My problem is very simple for a bash scripter or a old linux man, but not for me (novice and inexperienced). I need to store in a mysql database the output of "last" command, but the table where i need... (2 Replies)
Discussion started by: axl936
2 Replies

5. Web Development

Mysql question: Best way to update a column containing 8 million rows

Hi all, I was wondering if anyone knew a good/safe way to update a single column in a table that could contain upto 8 million rows... simple command like: UPDATE set blah=foo where bar=XXX; I will be running this on tables being written to and tables that have already been created. ... (3 Replies)
Discussion started by: muay_tb
3 Replies

6. Programming

declare a variable in mysql

i have created a script to insert 100K rows into mysql db. But the forst line where i declare the variable is giving error. I am new to mysql. Can anyone help me in this? the script is ====================================== DECLARE c INT(10) := 54; BEGIN WHILE c <... (4 Replies)
Discussion started by: amitranjansahu
4 Replies

7. UNIX for Dummies Questions & Answers

putting grep -c results number in a variable

I want to display "no results found" if a grep search of a name that the user inputs is not found anywhere in a certain file, Right now I have this, but doesn't seem to work. Im not sure what to change. read name results=grep -c $name file if ; then echo "No results found." exit... (1 Reply)
Discussion started by: busdude
1 Replies

8. Shell Programming and Scripting

Separating values from a file and putting to a variable

I am writing into a file testfile.txt values like ./XXXXXXCZ1/tprcm10c.bin ./XXXXXXCZ1_HOT/tprcm09c.bin ./XXXXXXCZ_cold/tprcm05c.bin I want to store the values of tprcm*.bin and XXXXXXCZ* in separate variables Can anybody Pls hlp me out with this ... Thanks (2 Replies)
Discussion started by: ultimatix
2 Replies
Login or Register to Ask a Question