title: Trigger in a database that should change values in a table in a different database?
body: <p>How to create a trigger that is activated by a change in a database which changes values in a table in a different database ? </p>
  
  <p>One database contains the table which has the login information (usernames, passwords) . When a user logs in, values in a table in another database is to be updated.</p>
  
  <p>How could this be achieved ?</p>
  
  <p><strong>[edit]</strong></p>
  
  <p>Sorry, yes, the two different databases are on the same database server.</p>
  
  <p><strong>[Updated]</strong></p>
  
  <p>I have <code>mainDB.users</code> table :</p>
  
  <pre><code>username | password | NumberLogins
  ---------|----------|--------------
           |          |
  </code></pre>
  
  <p>and a <code>otherDB.history</code> table :</p>
  
  <pre><code>username | points
  ---------|---------
           |
  </code></pre>
  
  <p>How do we increment the corresponding <code>points</code> after a user has logged in ?</p>
  
  <pre><code>USE `mainDB`;
  
  DROP TRIGGER IF EXISTS `updateUserInfo`;
  
  DELIMITER ||
  
  CREATE TRIGGER `updateUserInfo` 
      BEFORE UPDATE ON `users` 
      FOR EACH ROW
  
      BEGIN
          IF NEW.`NumberLogins`=5 THEN
  
              UPDATE `otherDB`.`history`
              SET `points` = `points` + 1,
              WHERE 
                `username`=NEW.`username`;
  
          END IF;
  
      END ||
  </code></pre>
  
  <p>I keep getting this error.</p>
  
  <pre><code> #1442 - Can't update table 'history' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. 
  </code></pre>