Re: There has to be a way to do this

2004-02-10 Thread Mike Tuller
Ok. I think I am close to getting this. Here is what I have.


MYSQL=/usr/local/mysql/bin/mysql  --user=$username --password=$password
--host=$server cetechnology

RESULT=$(echo select count(*) from hardware_assets where
ethernet_address='$ethernet_address'  | $MYSQL)
 if [ $RESULT = 0 ] ; then
 echo INSERT INTO hardware_assets (ethernet_address) VALUES
('$ethernet_address'); | $MYSQL
 else
 echo UPDATE hardware_assets SET operating_system='10.3.3'; | $MYSQL
fi

echo $RESULT

When I run this, it always does an update, and updates all records, not just
the ones that are matching $ethernet_address. I added the 'echo $RESULT' to
see what it was returning. It comes back with 'count(*) 1'. I change the if
statement to read 'if[$RESULT = count(*) 0 and the value for
$ethernet_address to a number that I do not have in the database. It does
not add the new ethernet address, and updates all of the records.

So that tells me that there is something wrong the value of $RESULT and the
comparison in the if statement. Further, if I change the value of $RESULT to
'12345' and change the if line to
if [ $RESULT = 12345 ] ; then
It adds a record to the database. So there is something wrong with what is
returned. Neither 0 or count(*) 0 seem to work. So, does anyone have an
idea as to what I need to put in for the comparison?


Mike

 From: gerald_clark [EMAIL PROTECTED]
 Date: Mon, 09 Feb 2004 14:28:27 -0600
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: There has to be a way to do this
 
 This is NOT a script that can run under mysql.
 It  is a bash script that calls mysql.
 
 MYSQL=/usr/local/mysql/bin/mysql  --user=$username --password=$password
 --host=$server cetechnology
 
 RESULT=`echo select count(*) from hardware_assets where
 ethernet_address='$ethernet_address' | $MYSQL
 if [ $RESULT = 0 ] ; then
   echo INSERT INTO hardware_assets (ethernet_address) VALUES
 ($ethernet_address); |$MYSQL
 else
   echo UPDATE hardware_assets SET operating_system='10.3.3'; | $MYSQL
 fi
 
 
 Mike Tuller wrote:
 
 I changed my script to this:
 
 /usr/local/mysql/bin/mysql  --user=$username --password=$password
 --host=$server 
 
 RESULT=`echo select count(*) from hardware_assets where
 ethernet_address='$ethernet_address' | cetechnology'
 if [ $RESULT = 0 ] ; then
echo INSERT INTO hardware_assets (ethernet_address) VALUES
 ($ethernet_address);
 else
echo UPDATE hardware_assets SET operating_system='10.3.3';
 fi
 
 Where cetechnology is the database. All the variables are set.
 
 When I run this, it starts the mysql client application,  with the mysql
 prompt. Nothing is inserted or updated in the database though.
 
 This is the same problem I had when I tried to do it this way, but I am not
 knowledgeable in shell scripting yet to know what I am doing wrong.
 
 
 
 
  
 
 From: gerald_clark [EMAIL PROTECTED]
 Date: Mon, 09 Feb 2004 11:11:24 -0600
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: There has to be a way to do this
 
 IF works on the selections not on the query.
 Select  IF(lastname='clark','Correct',''Incorrect'), firstname from
 namefile;
 
 You need to do the checking in your script.
 For example in bash:
 RESULT=`echo select count(*) from manefile where lastname='clark' |
 mysql database`
 if [ $RESULT = 0 ] ; then
  echo insert into namefile ...
 else
  echo update namefile ..
 fi
 
 
 Mike Tuller wrote:
 

 
 I have posted this question a few times, and have not seen the answer that
 I
 need.
 
 I have a shell script, that gathers information from systems, and I want
 that info to be entered into a database. I want it to check first to see if
 the data is already entered, and if not, add it. If it has already been
 entered, then update the record.
 
 I would think that some type of if/else statement would work, but I can't
 get the IF statement http://www.mysql.com/doc/en/IF_Statement.html to work
 correctly in MySql.
 
 Here is what I have:
 
 IF SELECT * FROM hardware_assets WHERE
 ethernet_address='$ethernet_address'
 IS NULL\
   THEN INSERT into hardware_assets (ethernet_address) VALUES
 ($ethernet_address)\
 ELSE\
   UPDATE hardware_assets SET operating_system='10.3.3'\
 END IF;
 
 I get back that I have an error in my SQL syntax. $ethernet_address is set,
 so that is not my problem.
 
 Does anyone know a way to go about this in SQL, or in a shell script? I
 don't want to do it in Perl or PHP.
 
 
 Thanks,
 Mike
 
 
 
 
  
 
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:
 http://lists.mysql.com/[EMAIL PROTECTED]
 

 
 
 
  
 
 
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



There has to be a way to do this

2004-02-09 Thread Mike Tuller
I have posted this question a few times, and have not seen the answer that I
need.

I have a shell script, that gathers information from systems, and I want
that info to be entered into a database. I want it to check first to see if
the data is already entered, and if not, add it. If it has already been
entered, then update the record.

I would think that some type of if/else statement would work, but I can't
get the IF statement http://www.mysql.com/doc/en/IF_Statement.html to work
correctly in MySql.

Here is what I have:

IF SELECT * FROM hardware_assets WHERE ethernet_address='$ethernet_address'
IS NULL\
THEN INSERT into hardware_assets (ethernet_address) VALUES
($ethernet_address)\
ELSE\
UPDATE hardware_assets SET operating_system='10.3.3'\
END IF;

I get back that I have an error in my SQL syntax. $ethernet_address is set,
so that is not my problem.

Does anyone know a way to go about this in SQL, or in a shell script? I
don't want to do it in Perl or PHP.


Thanks,
Mike


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: There has to be a way to do this

2004-02-09 Thread Mike Tuller
I changed my script to this:

/usr/local/mysql/bin/mysql  --user=$username --password=$password
--host=$server 

RESULT=`echo select count(*) from hardware_assets where
ethernet_address='$ethernet_address' | cetechnology'
if [ $RESULT = 0 ] ; then
echo INSERT INTO hardware_assets (ethernet_address) VALUES
($ethernet_address);
else
echo UPDATE hardware_assets SET operating_system='10.3.3';
fi

Where cetechnology is the database. All the variables are set.

When I run this, it starts the mysql client application,  with the mysql
prompt. Nothing is inserted or updated in the database though.

This is the same problem I had when I tried to do it this way, but I am not
knowledgeable in shell scripting yet to know what I am doing wrong.




 From: gerald_clark [EMAIL PROTECTED]
 Date: Mon, 09 Feb 2004 11:11:24 -0600
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: There has to be a way to do this
 
 IF works on the selections not on the query.
 Select  IF(lastname='clark','Correct',''Incorrect'), firstname from
 namefile;
 
 You need to do the checking in your script.
 For example in bash:
 RESULT=`echo select count(*) from manefile where lastname='clark' |
 mysql database`
 if [ $RESULT = 0 ] ; then
   echo insert into namefile ...
 else
   echo update namefile ..
 fi
 
 
 Mike Tuller wrote:
 
 I have posted this question a few times, and have not seen the answer that I
 need.
 
 I have a shell script, that gathers information from systems, and I want
 that info to be entered into a database. I want it to check first to see if
 the data is already entered, and if not, add it. If it has already been
 entered, then update the record.
 
 I would think that some type of if/else statement would work, but I can't
 get the IF statement http://www.mysql.com/doc/en/IF_Statement.html to work
 correctly in MySql.
 
 Here is what I have:
 
 IF SELECT * FROM hardware_assets WHERE ethernet_address='$ethernet_address'
 IS NULL\
THEN INSERT into hardware_assets (ethernet_address) VALUES
 ($ethernet_address)\
 ELSE\
UPDATE hardware_assets SET operating_system='10.3.3'\
 END IF;
 
 I get back that I have an error in my SQL syntax. $ethernet_address is set,
 so that is not my problem.
 
 Does anyone know a way to go about this in SQL, or in a shell script? I
 don't want to do it in Perl or PHP.
 
 
 Thanks,
 Mike
 
 
  
 
 
 
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:  
 http://lists.mysql.com/[EMAIL PROTECTED]
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: There has to be a way to do this

2004-02-09 Thread Mike Tuller
When I run this, it always updates the record, not matter what the value for
$ethernet_address is. I have tested this by changing the line under else to
echo Update Every time the script is run, it comes back with update.

I then we back and commented out the whole if/else statement and had only
the line for RESULT=, and then did echo $RESULT. It returns nothing. Not a 0
or a 1, nothing.

 From: gerald_clark [EMAIL PROTECTED]
 Date: Mon, 09 Feb 2004 14:28:27 -0600
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: There has to be a way to do this
 
 This is NOT a script that can run under mysql.
 It  is a bash script that calls mysql.
 
 MYSQL=/usr/local/mysql/bin/mysql  --user=$username --password=$password
 --host=$server cetechnology
 
 RESULT=`echo select count(*) from hardware_assets where
 ethernet_address='$ethernet_address' | $MYSQL
 if [ $RESULT = 0 ] ; then
   echo INSERT INTO hardware_assets (ethernet_address) VALUES
 ($ethernet_address); |$MYSQL
 else
   echo UPDATE hardware_assets SET operating_system='10.3.3'; | $MYSQL
 fi
 
 
 Mike Tuller wrote:
 
 I changed my script to this:
 
 /usr/local/mysql/bin/mysql  --user=$username --password=$password
 --host=$server 
 
 RESULT=`echo select count(*) from hardware_assets where
 ethernet_address='$ethernet_address' | cetechnology'
 if [ $RESULT = 0 ] ; then
echo INSERT INTO hardware_assets (ethernet_address) VALUES
 ($ethernet_address);
 else
echo UPDATE hardware_assets SET operating_system='10.3.3';
 fi
 
 Where cetechnology is the database. All the variables are set.
 
 When I run this, it starts the mysql client application,  with the mysql
 prompt. Nothing is inserted or updated in the database though.
 
 This is the same problem I had when I tried to do it this way, but I am not
 knowledgeable in shell scripting yet to know what I am doing wrong.
 
 
 
 
  
 
 From: gerald_clark [EMAIL PROTECTED]
 Date: Mon, 09 Feb 2004 11:11:24 -0600
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: There has to be a way to do this
 
 IF works on the selections not on the query.
 Select  IF(lastname='clark','Correct',''Incorrect'), firstname from
 namefile;
 
 You need to do the checking in your script.
 For example in bash:
 RESULT=`echo select count(*) from manefile where lastname='clark' |
 mysql database`
 if [ $RESULT = 0 ] ; then
  echo insert into namefile ...
 else
  echo update namefile ..
 fi
 
 
 Mike Tuller wrote:
 

 
 I have posted this question a few times, and have not seen the answer that
 I
 need.
 
 I have a shell script, that gathers information from systems, and I want
 that info to be entered into a database. I want it to check first to see if
 the data is already entered, and if not, add it. If it has already been
 entered, then update the record.
 
 I would think that some type of if/else statement would work, but I can't
 get the IF statement http://www.mysql.com/doc/en/IF_Statement.html to work
 correctly in MySql.
 
 Here is what I have:
 
 IF SELECT * FROM hardware_assets WHERE
 ethernet_address='$ethernet_address'
 IS NULL\
   THEN INSERT into hardware_assets (ethernet_address) VALUES
 ($ethernet_address)\
 ELSE\
   UPDATE hardware_assets SET operating_system='10.3.3'\
 END IF;
 
 I get back that I have an error in my SQL syntax. $ethernet_address is set,
 so that is not my problem.
 
 Does anyone know a way to go about this in SQL, or in a shell script? I
 don't want to do it in Perl or PHP.
 
 
 Thanks,
 Mike
 
 
 
 
  
 
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:
 http://lists.mysql.com/[EMAIL PROTECTED]
 

 
 
 
  
 
 
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



If statement

2004-02-05 Thread Mike Tuller
I need some help with this. Here is the information from the MySql manual.


IF search_condition THEN statement(s)
[ELSEIF search_condition THEN statement(s)]
...
[ELSE statement(s)]
END IF


IF implements a basic conditional construct. If the search_condition
evaluates to true, the corresponding SQL statement is executed. If no
search_condition matches, the statement in the ELSE clause is executed


Now what I want to do is search to see if a record exists, if it does,
update the record with new information, if not insert the data into the
table.

What confuses me above is that it says that if search condition is true,
then it will execute. How do I do a search and see if it is true? If I do
something like the following and it returns a result, does that mean it is
true?

SELECT * from table WHERE column='data';

Could someone give me a short example of what to do if this is not the case?


Mike Tuller


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: If Else statement

2004-01-27 Thread Mike Tuller
What I have is a shell script that gathers information from a computer, and
I want the script to check to see if there is currently a record that
already exists that has a certain Ethernet(MAC) address. I would also like
to have an ID number for the record that auto-increments so that I can have
an asset number to display on a web page. (Some assets I enter may not have
an Ethernet address because I am creating a database for hardware assets.
Computers, printers, etc., so I need to have an asset ID)

I have ethernet_address set as a Unique Key, and asset_id set as Primary_Key
and to auto-increment.

If I just use replace like below, every time the record is updated, the
asset number that is set to auto-increment is updated. So if it was 5
before, it is now 6. I don't what the asset_id to change of course.

/usr/local/mysql/bin/mysql  --user=$username --password=$password
--host=$server cetechnology -e \
REPLACE INTO hardware_assets (ethernet_address, operating_system)\
VALUES \
('$ethernet_address', '$operating_system');

I don't currently have MySql 4.1 running on my server, I have the 3.23.53
that comes with OS X Server 10.2, so if the suggestion you gave me is the
only way (or the best) I will have to upgrade the server. If there is
another way to do the same thing, please let me know.


Mike

 From: Egor Egorov [EMAIL PROTECTED]
 Date: Mon, 26 Jan 2004 15:40:54 +0200
 To: [EMAIL PROTECTED]
 Subject: Re: If Else statement
 
 Mike Tuller [EMAIL PROTECTED] wrote:
 I am trying write a shell script to check to see if a record exists and if
 it does, update information, and if it doesn't insert information. Is there
 a way to do an if else statement in MySql?
 
 
 If you have PRIMARY KEY or UNIQUE index, take a look at REPLACE and INSERT ..
 ON DUPLICATE KEY UPDATE statements:
 http://www.mysql.com/doc/en/REPLACE.html
 http://www.mysql.com/doc/en/INSERT.html
 
 INSERT .. ON DUPLICATE KEY UPDATE is supported since v4.1.0.
 
 
 
 -- 
 For technical support contracts, goto https://order.mysql.com/?ref=ensita
 This email is sponsored by Ensita.net http://www.ensita.net/
  __  ___ ___   __
 /  |/  /_ __/ __/ __ \/ /Egor Egorov
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
 /_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
  ___/   www.mysql.com
 
 
 
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:  
 http://lists.mysql.com/[EMAIL PROTECTED]
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



How to do a check to see if I update or insert

2004-01-26 Thread Mike Tuller
I am stuck on this problem, and know there has to be a solution.

I have a shell script, where I want to check to see if a record exists, and
if it does then update the record with new information. If it doesn't then
insert the information gathered by a script.

How, in MySql, using a shell script, can I do this?


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



If Else statement

2004-01-23 Thread Mike Tuller
I am trying write a shell script to check to see if a record exists and if
it does, update information, and if it doesn't insert information. Is there
a way to do an if else statement in MySql?

I'm stuck on how to do this. I don't want to write it in perl.


Mike


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Replace to update records

2004-01-22 Thread Mike Tuller
I have a shell script that will insert information about systems I have into
a MySql database. I wanted to have it so that the script could run daily,
and just update the records if a record for the particular system was
already in the database. This could make the script complex because I would
have to check to see if the record exists by matching the ethernet address.
If it does, then it would update the record, if it doesn't, it would add the
record.

The problem I have is that I want to have an auto-increment ID number that I
can have display on a web page, where you would click on the link that
displays the ID number of the computer to display details.

If I use replace, when I update the record, it also updates the ID, so what
was 4 is now 5. I don't want that to change.

Here is what I currently have.

/usr/local/mysql/bin/mysql  --user=$username --password=$password
--host=$server cetechnology -e \
REPLACE INTO hardware_assets (ethernet_address, operating_system,
boot_volume, computer_type, number_of_cpus, cpu_type, total_memory,
bus_speed, \
cpu_speed, L2_cache_size, serial_number, ip_address, network_name,
script_version, date_processed, asset_tag_number, department, location,
room_number) \
VALUES \
('$ethernet_address', '$operating_system', '$boot_volume',
'$computer_type', '$number_of_cpus',  '$cpu_type', '$total_memory',
'$bus_speed', \
'$cpu_speed', '$L2_cache_size', '$serial_number', '$ip_address',
'$network_name', '$script_version', '$date_processed', '$asset_tag_number',
\
'$department', '$location', '$room_number');


I am thinking it would be better to have the script search for all records
that match a certain ethernet address. If a record exists, then update the
record, and if one does not exist, then insert a record.

I understand how to select, insert, and update individually, but I am not
sure how to how to put it all together to do what I want this to do.
Something like this:

SELECT * WHERE ethernet_address = $ethernet_address
(if the number of results does not = 0)
UPDATE hardware_assets SET location='my location' WHERE
ethernet_address='$ethernet_address
Else
INSERT hardware_assets (ethernet_address, location) VALUES
($ethernet_address, $location)

Could someone help me finish these statements or show me a better way of
doing this?


Mike Tuller



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Connecting to remote server

2004-01-14 Thread Mike Tuller
I have the user hardware set to be able to connect to the database from any
host. That is why I am so confused as to why this doesn't work.

Mike

 From: Andrew Boothman [EMAIL PROTECTED]
 Date: Wed, 14 Jan 2004 01:04:36 +
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: Connecting to remote server
 
 Mike Tuller wrote:
 
 I have a shell script that is supposed to connect to a remote server running
 MySql 3.23.53. It comes up with an error ERROR 1045: Access denied for
 user: '[EMAIL PROTECTED]' (Using password: YES)
 
 The script looks like this:
 /usr/local/mysql/bin/mysql  --user=$username --password=$password
 cetechnology -e \
 
 That makes sense to me, I don't have permissions set correctly right for the
 $username (hardware). I know the password is set correctly.
 
 Then why am I able to connect to the server in the terminal with:
 /usr/local/mysql/bin/mysql -h 204.xxx.xxx.xxx -u hardware -p cetechnology
 And then enter my password.
 
 What is the difference?
 
 I'm not certain about this one (I'm not totally confident with MySQL's
 permission system myself). But it seems to me that assuming that the IP
 that you x'd out in your second example _is_ the IP of the local server
 in your first example then MySQL is going to treat them incoming
 connections from two different locations.
 
 One is going to be a connection from [EMAIL PROTECTED] the other is a
 connection from [EMAIL PROTECTED] - I think there's a good chance
 that MySQL will treat these as entirely different hosts to be GRANTed on
 despite the fact that they are actually the same physical machine.
 
 Therefore - if connections to 204.xxx.xxx.xxx work and connections to
 localhost don't, you need to GRANT the right permissions to
 [EMAIL PROTECTED]
 
 Have a look over the relevent section of the handbook for how to use GRANT
 
 HTH
 
 Andrew
 
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:  
 http://lists.mysql.com/[EMAIL PROTECTED]
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Connecting to remote server

2004-01-13 Thread Mike Tuller
I have a shell script that is supposed to connect to a remote server running
MySql 3.23.53. It comes up with an error ERROR 1045: Access denied for
user: '[EMAIL PROTECTED]' (Using password: YES)

The script looks like this:
/usr/local/mysql/bin/mysql  --user=$username --password=$password
cetechnology -e \

That makes sense to me, I don't have permissions set correctly right for the
$username (hardware). I know the password is set correctly.

Then why am I able to connect to the server in the terminal with:
/usr/local/mysql/bin/mysql -h 204.xxx.xxx.xxx -u hardware -p cetechnology
And then enter my password.

What is the difference?


Mike Tuller


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Check for data before inserting

2003-10-16 Thread Mike Tuller
I have a shell script that I have data entered into a database, and instead
of just entering in the data blindly, I want it to check to see if the item
it is entering exists already, and if it does, update the information rather
than inserting it. So I want to run a select statement, and if results come
back, have the data updated, and if not have it inserted.

I know how to do this in PHP with $query_total_rows. Is there some way in
SQL to do this, or do I need to figure out a way to do it in the shell
script?

Thanks,
Mike


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Check for data before inserting

2003-10-16 Thread Mike Tuller
Unless I am mistaken on REPLACE's use, I don't think that will work. The
example I have in the O'Reilly MySql book that I have shows this.

REPLACE(string, old, new)
Returns a string that has all occurances of the substring old replaced with
new(e.g., REPLACE('black jack', 'ack', 'oke') returns bloke joke).

I will explain what I am wanting to do.

I have a database that stores information about computers, and the
identifier is the ethernet address. I have a script that pulls the data from
a text file, and I want it so that if the ethernet address does not exist,
then it will insert the information into all columns. os_version,
ip_address, etc. If the ethernet address is not present, then it will update
the information in the fields.

I think I have to do a SELECT * from hardware_assets where ethernet_address
= $ethernet_address and then if there is a match, that row is updated, if
there is no match, then the data is inserted into a new row.


Mike

 From: Brent Baisley [EMAIL PROTECTED]
 Date: Thu, 16 Oct 2003 14:29:21 -0400
 To: Mike Tuller [EMAIL PROTECTED]
 Cc: MySql List [EMAIL PROTECTED]
 Subject: Re: Check for data before inserting
 
 It sound like you want to use REPLACE instead of the SELECT and
 INSERT/UPDATE combo. Replace will insert if the record doesn't exist
 and update if it does.
 
 
 On Thursday, October 16, 2003, at 01:27 PM, Mike Tuller wrote:
 
 I have a shell script that I have data entered into a database, and
 instead
 of just entering in the data blindly, I want it to check to see if the
 item
 it is entering exists already, and if it does, update the information
 rather
 than inserting it. So I want to run a select statement, and if results
 come
 back, have the data updated, and if not have it inserted.
 
 I know how to do this in PHP with $query_total_rows. Is there some way
 in
 SQL to do this, or do I need to figure out a way to do it in the shell
 script?
 
 Thanks,
 Mike
 
 -- 
 Brent Baisley
 Systems Architect
 Landover Associates, Inc.
 Search  Advisory Services for Advanced Technology Environments
 p: 212.759.6400/800.759.0577
 
 
 -- 
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:  
 http://lists.mysql.com/[EMAIL PROTECTED]
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Shell Script to Insert Data

2003-10-10 Thread Mike Tuller
I am trying to create a script that will insert data. Right now I am just
using something simple to test this out, but I can't get it to work. Here is
what I have.

mysql  --user=root --password= Database_Name;
INSERT INTO table_name (column_name) VALUES (value);

After I run the script, I check the data, and nothing was entered. When I
run each statement on it's own (not from a script file, but in the shell)
Everything seems to work. It just doesn't work when you try to run it from a
script.

Any ideas?

Mike Tuller


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Database design question

2002-06-27 Thread Mike Tuller

I am fairly new to this, so please bare with me on this.

I am designing a database that stores information about the computers I
manage, and am developing a PHP front end to add, view, and edit information
about the computers. One issue I ran into is designing the hard drive
information. Some computers have one hard drive, some have 2, 4, 16, etc. I
am wanting to learn how to deal with this the correct way, so I want to
create a separate table that stores the information about the drives, and
have a foreign key that specifies the computer that owns the drive.

I posted a message on the PHP-DB list, and received an answer that seems
confusing. It told me that I needed InnoDB to be able to deal with this
issue, but in the MySql documentation is says this:InnoDB provides MySQL
with a transaction-safe (ACID compliant) table handler with commit,
rollback, and crash recovery capabilities. Now having transactions
available would be nice, but that is not my problem now.

Now in another explaination on how to deal with relationships in MySql and
with PHP it shows that you use PHP to deal with the relationships. I always
thought that you let the database deal with the relationships, and not the
application you are writing. Which is correct? I would think that if I
created a relationship between tables, and I called for information on the
computer, I would automatically get all of the drive information. Am I
correct in this? Here is an example of the tables I have:

ComputerTable
computer_id - primary key
computer_name
etc.

HardDriveTable
drive_id - primary key
computer_id - foreign key
drive-capacity
etc.

If it is better to use the application code, I can do that, but I want to do
things the right way, not necessarily the easiest.


Mike


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: simple problem with mysql install

2001-01-28 Thread Mike Tuller

I posted the solution a couple of nights ago. The mysql folder and some of
the files within have the owner set to root. You need to change that to
mysql.

 From: anthony ortega [EMAIL PROTECTED]
 Date: 27 Jan 2001 22:46:25 -0800
 To: [EMAIL PROTECTED]
 Subject: simple problem with mysql install
 
 I recently upgraded to linux 7.0 which comes with mysql. Everytime that i try
 and start the mysql server it starts up then stops. when I try the mysql -user
 command it gives me a cant connect to mysql.sock error. any idea what is going
 wrong?
 
 Anthony Ortega
 (512)444-6238
 6700 B. Deatonhill
 Austin Tx, 78745
 Find the best deals on the web at AltaVista Shopping!
 http://www.shopping.altavista.com
 
 -
 Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)
 
 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
 [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Error 2002: can't connect to mysql.sock

2001-01-26 Thread Mike Tuller

I recently upgraded to RedHat 7, and now I can't get Mysql to start. I keep
getting error 2002: can't connect. I have looked at every piece of
documentation, and can't find the solution. The mysql.sock file exists, but
it still can't connect.

I have used the rpm of version 3.23.32 to install everything.

Thanks,
Mike


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Error 2002: can't connect to mysql.sock

2001-01-26 Thread Mike Tuller

You are right that RedHat is funny. 7 really seems weird. I tried for two
days to get everything going, (still am) and ran into all kinds of errors
with Mysql. I tried different versions, and had different problems on each.
I finally ran up2date to get everything update, and thought that would do
the trick. Not so.

I know, just configure it yourself, and don't use the rpms, but it is so
much better to maintain if you can use the rpms. At least for me. I don't
get lost trying to find where things are installed.

Back to the problem. I have tried doing what you said before, and tried it
again just now. Here is what I get.

[root@cypher mtuller]# /etc/rc.d/init.d/mysqld restart
Stopping MySQL:  [FAILED]
Starting MySQL:  [  OK  ]

All looks good!!..

Now I enter this.

[root@cypher mtuller]# mysql
ERROR 2002: Can't connect to local MySQL server through socket
'/var/lib/mysql/m
ysql.sock' (111)

I check to see mysql.sock is missing.

[root@cypher mtuller]# locate mysql.sock
/var/lib/mysql/mysql.sock

I've ran mysql_install_db, I've flushed the databases, reinstalled, updated,
prayed to the server gods, and still I get the same thing. I know mysql will
work, because I had Supportwizard's version of Mysql running earlier, but
wanted to switch to a generic version so that I could use it for other
things.

GRRR!

What next? Any ideas?


 From: "John Jensen" [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 Date: Fri, 26 Jan 2001 17:29:10 -0800
 To: [EMAIL PROTECTED]
 Subject: Re: Error 2002: can't connect to mysql.sock
 
 Redhat is funny. I have 7 and had tried everything in the books to
 get mysql back up and running after a shutdown. Fortunately, I had an
 experienced programmer who had helped me set it up. I queried him and
 set back this command:
 /etc/rc.d/init.d/mysqld restart
 That did the trick.
 It seems v.7 comes with all the packages I either had installed, or
 tried to install on 6.2, and everything else boots with Apache, but
 they left off mysql. Go figure.
 
 Apache also does not respond to the typical shutdown and restart
 commands given in the Apache manuals. Redhat has it set up to respond
 to their own commands.
 
 On 26 Jan 2001, at 19:10, Mike Tuller wrote:
 
 I recently upgraded to RedHat 7, and now I can't get Mysql to start. I
 keep getting error 2002: can't connect. I have looked at every piece
 of documentation, and can't find the solution. The mysql.sock file
 exists, but it still can't connect.
 
 I have used the rpm of version 3.23.32 to install everything.
 
 Thanks,
 Mike
 
 
 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)
 
 To request this thread, e-mail [EMAIL PROTECTED] To
 unsubscribe, e-mail
 [EMAIL PROTECTED] Trouble
 unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
 
 
 
 John Jensen
 Jensen's Directories
 www.college-without-classes.com/
 
 -
 Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)
 
 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
 [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php