Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no problem querying tables from different databases. </p> <pre><code>SELECT a.*, b.* FROM db1.table1 a INNER JOIN db2.table2 b ON (a.id = b.id) </code></pre> <p>Will run with no problems, as will your insert query.<br> <strong>However</strong> the user that starts the query needs to have proper access to the databases and tables involved. </p> <p>That means that user1 (who does the insert) has to be <code>grant</code>ed insert+select rights to table <code>{$joomla_db}.jos_muscol_artists</code> and select rights to <code>{$sam_db}.songlist</code></p> <p>If you don't want to expand the rights of your existing users, then you can just create a new <code>inserter</code> user that has the proper access rights to use both databases in the proper manner.<br> Only use this user to do inserts. </p> <p><strong>Alternative solution without adding users</strong><br> Another option is to create a blackhole table on db1 (the db you select from) </p> <pre><code>CREATE TABLE db1.bh_insert_into_db2 ( f1 integer, f2 varchar(255), f3 varchar(255) ) ENGINE = BLACKHOLE; </code></pre> <p>And attach a trigger to that that does the insert into db2.</p> <pre><code>DELIMITER $$ CREATE TRIGGER ai_bh_insert_into_db2_each ON bh_insert_into_db2 FOR EACH ROW BEGIN INSERT INTO db2.table2 (f1,f2,f3) VALUES (NEW.f1, NEW.f2, NEW.f3); END $$ DELIMITER ; </code></pre> <p>The insert into table <code>db2.table2</code> will happen with the access rights of the user how created the trigger. </p> <p><a href="http://dev.mysql.com/doc/refman/5.1/en/grant.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/grant.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload