RE: Triggers For Radius DB

2009-07-08 Thread Marcel Grandemange
In the last episode (Jul 07), Marcel Grandemange said:
 I hope someone can assist me.  I have a freeradius server running off
 mysql.  Now I would like to use triggers to negate some of the traffic
 logged within it.  I tried to use following as trigger..
 
 Create Trigger ftp
 BEFORE UPDATE ON radacct
 FOR EACH ROW
 BEGIN
 UPDATE radacct SET NEW.AcctInputOctets=(0 - NEW.AcctInputOctets) WHERE
NASPortId=21;
 UPDATE radacct SET NEW.AcctOutputOctets=(0 - NEW.AcctOutputOctets) WHERE
NASPortId=21;
 END;

 And Many variants of that but only ends up locking the db in someway with
 messages such as.
 
 Tue Jul  7 23:34:12 2009 : Error: rlm_sql_mysql: Cannot store result
 Tue Jul  7 23:34:12 2009 : Error: rlm_sql_mysql: MySQL error 'Can't update
table 'radacct' in stored function/trigger because it is already used by
statement which invoked this stored function/trigger.'

You don't want to UPDATE the table, since as you have seen it will cause
an
error.  The only row you can change in the table being modified in a
trigger
is the active row itself, and you must change its values by SETting
NEW.fieldname:

IF NEW.NASPortID = 21 THEN
 SET NEW.AcctInputOctets=(0 - NEW.AcctInputOctets);
 SET NEW.AcctOutputOctets=(0 - NEW.AcctOutputOctets):
END IF;


-- 
  Dan Nelson
  dnel...@allantgroup.com

Thank you so much, this worked 100%!

 

__ Information from ESET NOD32 Antivirus, version of virus signature
database 4223 (20090708) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: What OS is the best platform for MySQL ?

2009-07-08 Thread Ken Menzel

Dan Nelson wrote:

In the last episode (Jul 06), Blog Tieng Viet said:

I have been using MySQL on FreeBSD for 3 years and encounterd a lot of
problems related to thread management.  And 1 year ago, I found that my
FreeBSD box does not go well with any MySQL revision after 5.1.17-beta,
because the MySQL thread does not end although complied with
LINUX_THREADS.


Try building without LINUX_THREADS; that option shouldn't really be used
with FreeBSD 6 or newer.

Also This article may help if you have not yet abandoned Freebsd.  It 
shows how freebsd can outperform Linux in some cases.


http://people.freebsd.org/~kris/scaling/mysql.html

Ken


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: What OS is the best platform for MySQL ?

2009-07-08 Thread John Meyer
Ken Menzel wrote:
 Dan Nelson wrote:
 In the last episode (Jul 06), Blog Tieng Viet said:
 I have been using MySQL on FreeBSD for 3 years and encounterd a lot of
 problems related to thread management.  And 1 year ago, I found that my
 FreeBSD box does not go well with any MySQL revision after 5.1.17-beta,
 because the MySQL thread does not end although complied with
 LINUX_THREADS.

 Try building without LINUX_THREADS; that option shouldn't really be used
 with FreeBSD 6 or newer.

 Also This article may help if you have not yet abandoned Freebsd.  It
 shows how freebsd can outperform Linux in some cases.


Do we really need to bash OS's for MySQL.  Rather than questioning what
OS is best for MySQL we should ask how we can optimize MySQL for each OS.



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: What OS is the best platform for MySQL ?

2009-07-08 Thread bmurphy
There are merits to most of the common operating systems. In some ways
each of them perform better at various functions. The question becomes
which are you most comfortable and familiar with? That way you can work
most effectively with the operating system to fulfill the potential of
your databases.

If you aren't comfortable with any in particular, I would recommend you
learn your way around a Linux distribution. Again, not because it is
better than any other in particular, but because it is BY FAR the most
commonly deployed operating system running MySQL. It isn't even close in
terms of percentages. Behind it are Solaris and Windows. The most support
on the web is available for Linux simply because more people work on it.
But, if you are a Solaris, FreeBSD or Windows guru by all means as a
friend of mine says.. party on (on those platforms..)

Hope that helps.

Keith

 Ken Menzel wrote:
 Dan Nelson wrote:
 In the last episode (Jul 06), Blog Tieng Viet said:
 I have been using MySQL on FreeBSD for 3 years and encounterd a lot of
 problems related to thread management.  And 1 year ago, I found that
 my
 FreeBSD box does not go well with any MySQL revision after
 5.1.17-beta,
 because the MySQL thread does not end although complied with
 LINUX_THREADS.

 Try building without LINUX_THREADS; that option shouldn't really be
 used
 with FreeBSD 6 or newer.

 Also This article may help if you have not yet abandoned Freebsd.  It
 shows how freebsd can outperform Linux in some cases.


 Do we really need to bash OS's for MySQL.  Rather than questioning what
 OS is best for MySQL we should ask how we can optimize MySQL for each OS.










-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Client deleted database, semi high priority master slave question

2009-07-08 Thread Scott Haneda
A client deleted their database and did not have a slave in place for  
backup. No scheduled dumps either.


However, I have set up a slave to the master for one table. These  
tables hold DNS data for database driven DNS server features.


The master table is empty, the slave rightly saw the deletes and  
carried them out.


But I believe the replication logs on the slave, and also perhaps on  
the master should still be there. I'm not clear on how large these  
get, if they roll/truncate, etc.


Is there any way to restore the master up to the point the data was  
deleted? I can then set the slave to resync and they should be back  
where the left off.


There are a lot if records, not a lot of data since DNS data is so  
small. If I could restore the master It would prove quite helpful.  
Currently, all servers are down since DNS is not working, as a result  
of DNS being backed by MySql via DLZ/named.


Thanks for any suggestions.
--
Scott
Iphone says hello.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: Client deleted database, semi high priority master slave question

2009-07-08 Thread bmurphy
Hope the client learned the lesson about backups. it's a hard one to learn
sometimes.

If the binary logs on the slave were enabled when the table was populated
it should be possible to restore the table from the binary logs. If not,
and logging was turned on after the table was populated than you are out
of luck.

Keith

 A client deleted their database and did not have a slave in place for
 backup. No scheduled dumps either.

 However, I have set up a slave to the master for one table. These
 tables hold DNS data for database driven DNS server features.

 The master table is empty, the slave rightly saw the deletes and
 carried them out.

 But I believe the replication logs on the slave, and also perhaps on
 the master should still be there. I'm not clear on how large these
 get, if they roll/truncate, etc.

 Is there any way to restore the master up to the point the data was
 deleted? I can then set the slave to resync and they should be back
 where the left off.

 There are a lot if records, not a lot of data since DNS data is so
 small. If I could restore the master It would prove quite helpful.
 Currently, all servers are down since DNS is not working, as a result
 of DNS being backed by MySql via DLZ/named.

 Thanks for any suggestions.
 --
 Scott
 Iphone says hello.

 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:
 http://lists.mysql.com/mysql?unsub=bmur...@paragon-cs.com





-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: What OS is the best platform for MySQL ?

2009-07-08 Thread John Meyer
Carlos Williams wrote:
 On Wed, Jul 8, 2009 at 12:21 PM, John Meyerjohn.l.me...@gmail.com wrote:
 Do we really need to bash OS's for MySQL.  Rather than questioning what
 OS is best for MySQL we should ask how we can optimize MySQL for each OS.
 
 Did I mis-read an email or can someone please explain to me how anyone
 has bashed a specific OS? I have only seen responses with what people
 suggest. Many even offered helpful suggestions for the OP to stay on
 FreeBSD rather than users saying FreeBSD sucks and Linux is crap
 running MySQL. Great suggestions from everyone!


A thread with the title What OS is the best platform for MySQL pretty
much is a troll line for bashing OS's. I'm not saying the responses are
good, I'm just saying that the premise of the thread is a little misguided.

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



COUNT from 2 tables

2009-07-08 Thread b
I'm trying to get a count for columns in 2 tables at once. I have 
sessions and downloads tables and would like to get some basic stats.


mysql describe sessions;
+-+--+--+-+-++
| Field   | Type | Null | Key | Default | Extra  |
+-+--+--+-+-++
| id  | int(10) unsigned | NO   | PRI | NULL| auto_increment |
| created | datetime | YES  | | NULL||
| user_id | int(10) unsigned | NO   | MUL | NULL||
+-+--+--+-+-++
3 rows in set (0.01 sec)

mysql describe downloads;
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(10) unsigned | NO   | PRI | NULL| auto_increment |
| created  | datetime | YES  | | NULL||
| user_id  | int(10) unsigned | NO   | MUL | NULL||
| item_file_id | int(10) unsigned | NO   | MUL | NULL||
| session_id | int(10) unsigned | NO   | | NULL| 
|

| path | text | NO   | | NULL||
+--+--+--+-+-++
6 rows in set (0.01 sec)

mysql SELECT MONTHNAME(created) AS month, COUNT(*) AS num_logins FROM 
sessions GROUP BY month;

+---++
| month | num_logins |
+---++
| July  |  6 |
| June  |214 |
| May   |150 |
+---++
3 rows in set (0.00 sec)

mysql SELECT MONTHNAME(created) AS month, COUNT(*) AS num_downloads 
FROM downloads GROUP BY month;

+---+---+
| month | num_downloads |
+---+---+
| June  |   389 |
| May   |   220 |
+---+---+
2 rows in set (0.01 sec)


In trying to get the count from both tables at once, the logins are no 
longer being summed as expected:


mysql SELECT MONTHNAME(s.created) AS month, COUNT(s.id) AS num_logins, 
COUNT(d.id) AS num_downloads FROM sessions AS s LEFT JOIN downloads AS d 
ON d.session_id = s.id GROUP BY month;

+---++---+
| month | num_logins | num_downloads |
+---++---+
| July  |  6 | 0 |
| June  |539 |   389 |
| May   |350 |   220 |
+---++---+
3 rows in set (0.31 sec)


Is this possible to do without using a sub-query?

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



RE: COUNT from 2 tables

2009-07-08 Thread Gary Smith
Off the top of my head, try this.

SELECT 
MONTHNAME(s.created) AS month, 
sum(if(ifnull(s.id,0)  0, 1, 0)) AS num_logins,
sim(if(ifnull(d.id, 0) 0, 1, 0)) AS num_downloads 
FROM sessions AS s LEFT JOIN downloads AS d
ON d.session_id = s.id GROUP BY month


From: b [my...@logi.ca]
Sent: Wednesday, July 08, 2009 12:21 PM
To: mysql@lists.mysql.com
Subject: COUNT from 2 tables

I'm trying to get a count for columns in 2 tables at once. I have
sessions and downloads tables and would like to get some basic stats.

mysql describe sessions;
+-+--+--+-+-++
| Field   | Type | Null | Key | Default | Extra  |
+-+--+--+-+-++
| id  | int(10) unsigned | NO   | PRI | NULL| auto_increment |
| created | datetime | YES  | | NULL||
| user_id | int(10) unsigned | NO   | MUL | NULL||
+-+--+--+-+-++
3 rows in set (0.01 sec)

mysql describe downloads;
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(10) unsigned | NO   | PRI | NULL| auto_increment |
| created  | datetime | YES  | | NULL||
| user_id  | int(10) unsigned | NO   | MUL | NULL||
| item_file_id | int(10) unsigned | NO   | MUL | NULL||
| session_id | int(10) unsigned | NO   | | NULL|
 |
| path | text | NO   | | NULL||
+--+--+--+-+-++
6 rows in set (0.01 sec)

mysql SELECT MONTHNAME(created) AS month, COUNT(*) AS num_logins FROM
sessions GROUP BY month;
+---++
| month | num_logins |
+---++
| July  |  6 |
| June  |214 |
| May   |150 |
+---++
3 rows in set (0.00 sec)

mysql SELECT MONTHNAME(created) AS month, COUNT(*) AS num_downloads
FROM downloads GROUP BY month;
+---+---+
| month | num_downloads |
+---+---+
| June  |   389 |
| May   |   220 |
+---+---+
2 rows in set (0.01 sec)


In trying to get the count from both tables at once, the logins are no
longer being summed as expected:

mysql SELECT MONTHNAME(s.created) AS month, COUNT(s.id) AS num_logins,
COUNT(d.id) AS num_downloads FROM sessions AS s LEFT JOIN downloads AS d
ON d.session_id = s.id GROUP BY month;
+---++---+
| month | num_logins | num_downloads |
+---++---+
| July  |  6 | 0 |
| June  |539 |   389 |
| May   |350 |   220 |
+---++---+
3 rows in set (0.31 sec)


Is this possible to do without using a sub-query?

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=g...@primeexalia.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



RE: Client deleted database, semi high priority master slave question

2009-07-08 Thread Daevid Vincent
 

 -Original Message-
 From: Scott Haneda [mailto:talkli...@newgeo.com] 
 Sent: Wednesday, July 08, 2009 9:50 AM
 To: mysql@lists.mysql.com
 Subject: Client deleted database, semi high priority master 
 slave question
 
 A client deleted their database and did not have a slave in 
 place for  
 backup. No scheduled dumps either.

Ouch.

I know it comes a little too late, but as a preventive measure going
forward, I offer up my daily crontab backup script:

http://www.daevid.com/content/examples/daily_backup.php



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: COUNT from 2 tables

2009-07-08 Thread b

On 07/08/2009 03:33 PM, Gary Smith wrote:

Off the top of my head, try this.

SELECT
MONTHNAME(s.created) AS month,
sum(if(ifnull(s.id,0)  0, 1, 0)) AS num_logins,
sim(if(ifnull(d.id, 0)  0, 1, 0)) AS num_downloads
FROM sessions AS s LEFT JOIN downloads AS d
ON d.session_id = s.id GROUP BY month



Nope, I'm still getting those same incorrect sums. Thanks, though. It 
seems to me that the problem is that I'm grouping by the month for one 
table but counting from both.


I'd paste the output here but I just upgraded Fedora and the BETA (wtf?) 
version of Thunderbird crashes when I paste into an email (how the 
earlier paste worked I don't know).


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Replication switch Master to slave and back

2009-07-08 Thread Cantwell, Bryan
I have successfully set up a replication master/slave scenario with my MySQL 
5.0.51a
Now in the event of a fail over to the slave (an identical appliance), I want 
the old master to become the slave for an eventual switch back the other way.
Would it really take the same process to keep the old master up to date with 
the new one? Or is there a way to bring it up to date with the new machine 
without a mysqldump or copying data files? 

I have binary logging running on both machines in hopes that I could just tell 
the new slave how to catch up with the new master...
Any assistance here?

thanks

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: Client deleted database, semi high priority master slave question

2009-07-08 Thread Scott Haneda

On Jul 8, 2009, at 12:49 PM, Daevid Vincent wrote:


Ouch.

I know it comes a little too late, but as a preventive measure going
forward, I offer up my daily crontab backup script:

http://www.daevid.com/content/examples/daily_backup.php



They move a lot of data, so scheduled dumps were not really an  
option.  I wrote a proposal to use two databases, one is the primary  
acting as a DNS 1, and the second is the slave, acting as DNS 2.  I  
then wanted to add a 3rd slave server, that was a hot standby, in case  
the primary went down.  It would hold copies of all databases.


This would be on a raid, and on a schedule, it would also do dumps,  
which could take as long as they want, since this machine was not  
being hit at all.


This was not implemented for some reason.  I will look at your  
scripts, thanks again.

--
Scott * If you contact me off list replace talklists@ with scott@ *


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: Client deleted database, semi high priority master slave question

2009-07-08 Thread Scott Haneda

On Jul 8, 2009, at 12:49 PM, Daevid Vincent wrote:


I know it comes a little too late, but as a preventive measure going
forward, I offer up my daily crontab backup script:

http://www.daevid.com/content/examples/daily_backup.php



FYI, this link does not work in Safari.
--
Scott * If you contact me off list replace talklists@ with scott@ *


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: Replication switch Master to slave and back

2009-07-08 Thread Aaron Blew
The simplest method may be to set them up in a multi-master configuration,
similar to what's documented here:
http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html

This way you won't have to worry about switching between two masters in a
failover scenario since they're both writable.

-Aaron

On Wed, Jul 8, 2009 at 1:38 PM, Cantwell, Bryan bcantw...@firescope.comwrote:

 I have successfully set up a replication master/slave scenario with my
 MySQL 5.0.51a
 Now in the event of a fail over to the slave (an identical appliance), I
 want the old master to become the slave for an eventual switch back the
 other way.
 Would it really take the same process to keep the old master up to date
 with the new one? Or is there a way to bring it up to date with the new
 machine without a mysqldump or copying data files?

 I have binary logging running on both machines in hopes that I could just
 tell the new slave how to catch up with the new master...
 Any assistance here?

 thanks

 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql?unsub=aaronb...@gmail.com




Re: Replication switch Master to slave and back

2009-07-08 Thread Marcus Bointon

On 8 Jul 2009, at 22:26, Aaron Blew wrote:

The simplest method may be to set them up in a multi-master  
configuration,

similar to what's documented here:
http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html

This way you won't have to worry about switching between two masters  
in a

failover scenario since they're both writable.



That setup works very well for me, but I also use google's mmm on top  
of it so that the switch is transparent to client apps. Works  
beautifully.


https://launchpad.net/mysql-mmm

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
UK resellers of i...@hand CRM solutions
mar...@synchromedia.co.uk | http://www.synchromedia.co.uk/




smime.p7s
Description: S/MIME cryptographic signature


CONCAT with IF?

2009-07-08 Thread Matt Neimeyer
I want to store the product version that an article applies to and a
comparison operator in my news system. But I can't wrap my head around
the where clause...

Here's what I've tried...

CREATE TABLE test (version char(10), direction char(2));

select concat(6.0,direction,version) as operation from test;

+-+
|operation|
+-+
| 6.0=6.0
| 6.0=6.0
| 6.06.1
| 6.06.2
+-+

But when I do select if(concat(6.0,direction,version),Y,N) from
test I ALWAYS get Y... which means I wouldn't get any meaningful
results if I used it in a where clause...

Any ideas on ways I can do this?

Thanks!

Matt

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



RE: COUNT from 2 tables

2009-07-08 Thread Gary Smith
Create a view or sub select, denormalizing the data and then group it.

select month, sum(login) as num_logins, sum(download) as num_downloads
from
(
select 
monthname(s.created) as month_name
, if(ifnull(s.id, 0)  0, 1, 0) as login
, if(ifnull(d.id, 0)  0, 1, 0) as download
from sessions s left join downloads d
on s.id = d.session_id
)
group by month name;

which is the left table?  downloads or logins?  If logins shouldn't it be on 
the left side of the ON statement? (I'm not sure)  My understanding is that is 
the ON statement that runs the left join, not which table is listed first (I 
could be wrong though -- chime in if you know the definitive answer please).

Anyway, try this and see if it gets you closer.

From: b [my...@logi.ca]
Sent: Wednesday, July 08, 2009 12:55 PM
To: mysql@lists.mysql.com
Subject: Re: COUNT from 2 tables

On 07/08/2009 03:33 PM, Gary Smith wrote:
 Off the top of my head, try this.

 SELECT
 MONTHNAME(s.created) AS month,
 sum(if(ifnull(s.id,0)  0, 1, 0)) AS num_logins,
 sim(if(ifnull(d.id, 0)  0, 1, 0)) AS num_downloads
 FROM sessions AS s LEFT JOIN downloads AS d
 ON d.session_id = s.id GROUP BY month


Nope, I'm still getting those same incorrect sums. Thanks, though. It
seems to me that the problem is that I'm grouping by the month for one
table but counting from both.

I'd paste the output here but I just upgraded Fedora and the BETA (wtf?)
version of Thunderbird crashes when I paste into an email (how the
earlier paste worked I don't know).

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=g...@primeexalia.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



RE: CONCAT with IF?

2009-07-08 Thread Gavin Towey
Something like:

SET @version = 6.0;
SELECT CASE direction WHEN '' THEN IF( @version  version, 'Y', 'N') WHEN '' 
THEN IF (@version  version, 'Y','N)  ... END AS operation FROM test;

-Original Message-
From: Matt Neimeyer [mailto:m...@neimeyer.org]
Sent: Wednesday, July 08, 2009 2:45 PM
To: mysql@lists.mysql.com
Subject: CONCAT with IF?

I want to store the product version that an article applies to and a
comparison operator in my news system. But I can't wrap my head around
the where clause...

Here's what I've tried...

CREATE TABLE test (version char(10), direction char(2));

select concat(6.0,direction,version) as operation from test;

+-+
|operation|
+-+
| 6.0=6.0
| 6.0=6.0
| 6.06.1
| 6.06.2
+-+

But when I do select if(concat(6.0,direction,version),Y,N) from
test I ALWAYS get Y... which means I wouldn't get any meaningful
results if I used it in a where clause...

Any ideas on ways I can do this?

Thanks!

Matt

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=gto...@ffn.com


The information contained in this transmission may contain privileged and 
confidential information. It is intended only for the use of the person(s) 
named above. If you are not the intended recipient, you are hereby notified 
that any review, dissemination, distribution or duplication of this 
communication is strictly prohibited. If you are not the intended recipient, 
please contact the sender by reply email and destroy all copies of the original 
message.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Another Trigger Question!

2009-07-08 Thread Marcel Grandemange
Good Day once again.

 

Im needing assistance again with triggers!

 

 

Create Trigger hostchange

BEFORE UPDATE ON host

FOR EACH ROW

BEGIN

IF NEW.status != OLD.status THEN

use smsgw;

insert into outbox (number, insertdate, text, phone, dreport) VALUES
('0836075144', '', 'HostDown', '1', '1'));

END IF;

END;

 

 

I have my idea of a trigger above that for obvious reasons wont work ,
however describes what im trying to do best!

Im monitoring a value status and if it changes id like to insert a record
into a entirely separate table in a separate DB.

 

Any ideas on how syntax should be?

Also anyone know of any good ebooks that describe triggers in depth? I find
most info I find on web is simplistic at best or simply don't explain well
anough for my level!

 

 

Regards



Re: COUNT from 2 tables

2009-07-08 Thread b

On 07/08/2009 06:11 PM, Gary Smith wrote:

Create a view or sub select, denormalizing the data and then group it.

select month, sum(login) as num_logins, sum(download) as num_downloads
from
(
select
monthname(s.created) as month_name
, if(ifnull(s.id, 0)  0, 1, 0) as login
, if(ifnull(d.id, 0)  0, 1, 0) as download
from sessions s left join downloads d
on s.id = d.session_id
)
group by month name;

which is the left table?  downloads or logins?  If logins shouldn't it be on 
the left side of the ON statement? (I'm not sure)  My understanding is that is 
the ON statement that runs the left join, not which table is listed first (I 
could be wrong though -- chime in if you know the definitive answer please).

Anyway, try this and see if it gets you closer.


I had to change month_name to month and add AS foo just before the 
GROUP BY (Every derived table must have its own alias) but still no 
joy. I'm still getting those same incorrect numbers.


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org



Re: Another Trigger Question!

2009-07-08 Thread Dan Nelson
In the last episode (Jul 09), Marcel Grandemange said:
 Create Trigger hostchange
 BEFORE UPDATE ON host
 FOR EACH ROW
 BEGIN
 IF NEW.status != OLD.status THEN
 use smsgw;
 insert into outbox (number, insertdate, text, phone, dreport) VALUES
 ('0836075144', '', 'HostDown', '1', '1'));
 END IF;
 END;
 
 I have my idea of a trigger above that for obvious reasons wont work ,
 however describes what im trying to do best!
 
 Im monitoring a value status and if it changes id like to insert a record
 into a entirely separate table in a separate DB.

insert into smsgw.outbox [...]
 
-- 
Dan Nelson
dnel...@allantgroup.com

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org