473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to store Mysql Database Field value to Shell Script variable

38 New Member
Hi Bytes.. i have need to assign Mysql Database DataField value to shell script variable .

is it possible ? i have tried like this .. got error..
Expand|Select|Wrap|Line Numbers
  1. #!bin/sh
  2.  
  3. password=xxx
  4. mysql -u root -p$password -h 192.168.1.8 << y
  5. use dbssys;
  6. d ="`select mem from profile` ";
  7. echo $d
  8. quit
  9. y
  10.  
  11.  
Got Output like this..

test.sh: command substitution: line 1: syntax error near unexpected token `from'
test.sh: command substitution: line 1: `select mem from profile'
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd =" "' at line 1
Jan 2 '09 #1
8 13654
micmast
144 New Member
The problem is that the backticks will execute the code within and select mem from profile is no valid linux bash/shell command. Try escaping them with a \
Jan 2 '09 #2
xtremebass
38 New Member
i cant get you clearly.. if you dont mind..can you please correct that particular line and send me ..
Jan 2 '09 #3
micmast
144 New Member
micmast@plato:~ $ d="\`select mem from profile\`";
micmast@plato:~ $ echo $d
`select mem from profile`
Jan 2 '09 #4
xtremebass
38 New Member
Hi i didnt solve the problem yet.. after applying changes that you have said.. any other solution for this..
Jan 6 '09 #5
gpraghuram
1,275 Recognized Expert Top Contributor
Why canyou use isql or fsql to connect to the DB and get the values to the variable you expect?

raghu
Jan 7 '09 #6
xtremebass
38 New Member
i am not using fsql or isql for my project. actually i am doing Linux system oriented project and storing the values in Mysql . i need to compare the values that stored in mysql and recent values get from the linux .. so thats why i am looking for a solution? can u suggest some hint ? method /way proceed further??
Jan 7 '09 #7
ashitpro
542 Recognized Expert Contributor
Try using this line...

result=$(mysql -u $user_name $db_name -p$password -sN -e “select mem from profile”)
Jan 7 '09 #8
stmarc23
1 New Member
In a script just write this, and play with the mysql options to get what you want.

SHELLVARIABLE=` mysql --skip-column-names dataBase -e "SELECT COUNT(*) from TableAAA"`

and then u can do somethink like

ehco $SHELLVARIABLE

This is a tip.

Bye.
Dec 15 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2946
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But not update. Here is a copy of the script I am using. I do not know what version of MySQL my host is running nor do I have Shell Access to it. I
20
3907
by: de Beers | last post by:
mysql_query("DELETE FROM cart WHERE ItemId=$ItemId"); There is the code but the result in my databse is that the ID number changes from, lets say, 77 to 78 with 78's contents being empty. Therefore when I look at the results - the deleted ID77 is gone but now I have ID78 with no content! Does anyone know why and how do I make it stop? ...
2
5036
by: RootShell | last post by:
Hello First of all i know that PHP is a server side, and JavaScript is a Client side programming language, but i need to know if there is any way i can add the variable "countDownInterval" from this particular FULL code into a MySQL field. Here's the drill: I have a timer on a PHP webpage, and i want to prevent the user from doing a
3
10297
by: the.natalie | last post by:
Hi. I am a newbie to mysql, cron, and shell scripting, so please bear with me. I have a script that is used for updating an image directory based on contents in a database. The script does the following: runs several queries against different tables in a database; returns several lists of pictures being used in the database; removes any...
5
2262
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve this but it's clear that I'm misunderstanding $variable persistence. I posted a similar enquiry over at alt.php.mysql, but I guess this is a more...
11
3747
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result = mysql_query("select * from $tableInfo") ; for ($i = 0; $i < mysql_num_rows($result); $i++) {
39
5836
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
13821
JamieHowarth0
by: JamieHowarth0 | last post by:
I have been trying to find a solution to this on the Internet for months. Literally, ages and ages and ages, praying that someone in the open-source community has enough knowledge to put together an LDAP connector for MySQL Community to connect to Active Directory. Alas, nothing. So I figured I'd try doing something similar. My business problem...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.