Updated: Multiple Databases (1.0.1)

A new version of the Multi-DB package is available. If you’re getting errors with 1.0.0 this should solve the problem.

And yes I actually mean ‘multi-db’ this time :wink:

Thanks,

Andrew

  • drmike
    • DEV MAN’s Mascot

    OK, I’m a bit lost about lan_host and host within wp-config.php. If the db is on the same box as the site, I’m assuming that we put that IP address within host. What do we put within lan_host? Also if the db is on a second box that is on a lan (Well at least not publicly accessable but on a private IP address) what do we put for the host number?

  • drmike
    • DEV MAN’s Mascot

    Not for me. Getting the “Not installed, here’s a link to the debugging file.” error message. :slight_frown:

    – Someone please confirm that db.php and db-config.php goes in wp-content and not where we’ve been putting those files. Just seems strange to me.

    – I also note that the example files list dc_ip not as an ip address but a class c. Is that correct?

    add_dc_ip(‘72.34.37.’, ‘dc1’:wink:;

  • drmike
    • DEV MAN’s Mascot

    I found the debugging lines and I do confirm that it is pulling in the database information fine. I also found where db.php calls the config file so I understand that the files do belong within the wp-content directory.

    I’m using the ip address of the server for both host and lan_host.

    It’s weird….

    Using r1295 which came out of the trac this morning.

  • Luke
    • The Crimson Coder

    1.0.1 is working just fine for me.

    dp and db-config do go in wp-content. WP (at some point) put in a check for a db.php file in wp-content, which if it exists is loaded instead of wp-includes/wpdb.php.

    Nice hook there, I think, and makes upgrading with this plugin much easier.

  • Andrew
    • Champion of Loops
      Nice hook there, I think, and makes upgrading with this plugin much easier.

    They added the hook for HyperDB but it works just fine for this one as well.

      What did you put in for the add_dc_ip line?

    Just the class c.

      How about the 2 hosts calls when you do the add database lines?

    One is the internal/lan IP (ex: 192.168.1.102) and the other is the remote/public IP (ex: 72.113.82.201). The lan IP is tried first and then the remote/public IP.

    Thanks,

    Andrew

  • drmike
    • DEV MAN’s Mascot

    Let me go try that when I get to the university library. (*grumble* dumb hacked email station….)

    I seem to remember that Donncha made some changes to the database files after the release. I’m using the latest out of trac. What version is this up against? (I can give specifics later on. Locked down terminal.)

    edit: Damn frigging keyboard. *grumble* *grumble* I did notice that I was unable to transfer database tables between the databases. I’m wondering if something else is wrong.

  • trent
    • Site Builder, Child of Zeus

    I have held off on updating this one until now, so just wanted a small bit of clarification on some things before I get going as I am using a replicate server as well.

    1) The data centers would have the class “c” address such as:

    add_dc_ip(‘72.50.100.’, ‘master’:wink:;

    add_dc_ip(‘72.50.101.’, ‘slave’:wink:;

    The globals would be something like the following with the slave with no write access?

    add_db_server(‘global’, ‘master’, 1, 1,’72.50.100.1′,’192.168.0.101′, ‘wpmu_global’, ‘user’, ‘pass’:wink:;

    add_db_server(‘global’, ‘slave’, 1, 0,’72.50.101.1′,’192.168.0.101′, ‘wpmu_global’, ‘user’, ‘pass’:wink:;

    What if you don’t use the local IP’s at all (that I know of) could you use?:

    add_db_server(‘global’, ‘master’, 1, 1,’72.50.100.1′,’localhost’, ‘wpmu_global’, ‘user’, ‘pass’:wink:;

    add_db_server(‘global’, ‘slave’, 1, 0,’72.50.101.1′,’localhost’, ‘wpmu_global’, ‘user’, ‘pass’:wink:;

    Same would be for the specific databases after, just wanted a “slight” clarification on syntax and then I am off to the races.

    Thanks,

    Trent

  • Andrew
    • Champion of Loops
      1) The data centers would have the class “c” address such as:

    Are you setting it up so that the master and slave servers are in two separate datacenters?

      What if you don’t use the local IP’s at all (that I know of) could you use?:

    Hostnames will do just fine. I just used IPs as examples hoping it would make it easier for most people.

    Thanks,

    Andrew

  • trent
    • Site Builder, Child of Zeus

    Thanks Andrew. Just a quick note that the “newdb_prefix” in the move_blogs.php script is still a little bonkers (as mentioned before) because if you put wpmu_ in there, it won’t connect to the global as it adds another underscore on line 101:

    $this_blog_new_db = $newdb_prefix."_global";

    If you put the newdb_prefix as just wpmu without the underscore, it doesn’t connect to the other db’s (wpmua versus wpmu_a). Just a quick note :wink:

    Thanks

    Trent

  • trent
    • Site Builder, Child of Zeus

    Everything is working great and the data is now working with the multiple DB’s for sure. I am wondering about the replication though as I shut down the master DB server to see if it would access the slave and just gave me the “Could Not Connect To Database” error. I am testing just 16 DB’s on this install and have 2 entries for everything (for for master with read/write and one for slave with read but not write).

    Any ideas?

    Trent

  • Andrew
    • Champion of Loops

    Thanks :slight_smile:

    I’m sure there’s still a few bugs lurking around because the advanced features (replication, etc) really haven’t been tested a lot.

    Hopefully this coming week I’ll have time to setup a test environment.

    Thanks,

    Andrew

  • drmike
    • DEV MAN’s Mascot

    Are you getting a specific error message?

    Just the “No current site, here’s the link to the debugging page if your the site owner” error. I took it off for the time being but will work on it if I have time today.

    This is the cynix/cynix.uni.cc domain although the plugin is not currently installed.

  • Andrew
    • Champion of Loops

    If you can’t get it to work this afternoon just send over the details (db names, users, etc) and I’ll take a look. You’ve never had a problem with it before so either something is not clear or there’s a problem. Either way it needs to get fixed.

    Thanks,

    Andrew

  • Luke
    • The Crimson Coder

    Speaking of problems, I had a query (worked in 1.3/2.3) that grabbed post tags and categories from the taxonomy tables.

    Seems something went amiss with upgrading to 1.5, and running multiple db’s.

    For example, it was trying to connect to db_d4 to get those tables, when actually they were in db_8c.

    I ended up taking that query out, and just using wp functions to get the tags/cats, but it was certainly weird to say the least.

    Nothing special in the query, either. Reading the wpdb object did show that the full table names were correctly mapped in the object, being wp_blogid_tablename. So I’m not sure what was causing it, but something certainly was.

    Could have been a fluke, but I can’t say for sure. I’ve got similar code running on another site, so I’ll keep an eye on it and see what happens. However, the symptoms aren’t present on that one that were on the one that was having issues.

  • Andrew
    • Champion of Loops

    Make sure you’re using either Multi-DB 1.0.0 or 1.0.1. Multi-DB 0.9.9 used $wpdb->blogid in a few placed to determine the blog the query is meant for. This idea was borrowed from HyperDB but I switched it back to the older regular expression code to grab the blog id for greater accuracy.

    Basically HyperDB depends on plugins to use the the ‘switch_to_blog’ function before grabbing data from different blogs. That’s great and all but it’s much easier to just use ‘$wpdb->base_prefix . $tmp_blog_id . “_posts’ than it is to switch to a blog and then use ‘$wpdb->posts’.

    Edit: If you already are using one of the later versions then I’m really not sure what could have caused that. If it happens again send me the query and I’ll see why it’s not directing it to the correct db.

    Thanks,

    Andrew

  • Luke
    • The Crimson Coder

    That’s what is strange. It’s the latest.

    The query wasn’t anything fancy, grabbing from some weird blog or something. It was just a straight query to grab tags for a specific post id.

    $wpdb->get_results("
    SELECT c.name AS cat_name, c.slug AS cat_slug, t.taxonomy AS cat_type
    FROM ($wpdb->terms AS c, $wpdb->term_taxonomy AS t)
    LEFT JOIN $wpdb->term_relationships AS p ON (t.term_taxonomy_id = p.term_taxonomy_id)
    WHERE p.object_id = '{$post_id}' AND ( t.term_id = c.term_id )
    ");

    For those tables, it was trying to connect to the wrong db, but I have no idea why. It could have been a plugin or something that ran before it, that did a switch to blog and didn’t switch back, but that would seem strange.

    What’s really strange, is that db_d4 doesn’t have any tables in it at all. It’s empty. So that makes it even more strange.

    I dunno about grabbing the blog id, but to me it would seem easiest to strip the base prefix from the table name, explode by the underscore of that result, and then grab the [0] key of the resulting array. If it’s numeric (is_numeric), then you know it’s a blog table, and there’s the blog id.

    Not sure how hyper db was doing it though.

  • Andrew
    • Champion of Loops
      I dunno about grabbing the blog id, but to me it would seem easiest to strip the base prefix from the table name, explode by the underscore of that result, and then grab the [0] key of the resulting array. If it’s numeric (is_numeric), then you know it’s a blog table, and there’s the blog id.

    That’s pretty much how the current version does it, just with a bit more code.

    I will note that some strange things have happened with JOIN queries.

    Thanks,

    Andrew

  • Luke
    • The Crimson Coder

    I could understand a join across tables not in the same database, but this one had me stupified for a bit. Luck would have it that I could use the template functions instead, which worked out OK.

    While it doesn’t hunt down the issue, at least it’s back working.

    I’ve got this particular query on another site for testing, and haven’t seen any problems. Guess I’ll have to keep an eye on it.

  • Luke
    • The Crimson Coder

    Following up on the above error with mixed up db’s, I wonder if it might not have to do with something about the way that the blog_id is determined, thus the db hash and globalized tables?

    Getting an error now on a table that is global, and listed as such, but it’s again trying to connect to the wrong database.

    The table name is formatted like: wp_table_name.

    wp_ is the prefix, table_name is the table name. It should be hitting the global db, but it’s trying to hit db_d4 instead.

    Makes me wonder if a table name has an underscore in it, if somehow it’s returning a blank or something for a blog_id.

    Strange thing here is that it’s a global table, so should be explicitly hitting the global db.

    Only thing in common other than an underscore in the table name would be that the query is again a join. As a note, the join is across tables in the same db (global).

  • Andrew
    • Champion of Loops

    I probably need to toss an is_numeric in their. Although that really shouldn’t be needed because global tables are supposed to be checked before blog tables.

    I’ve got a small list multi-db of stuff I’ve got to look at so I’ll just add this to it.

    Thanks,

    Andrew

  • Luke
    • The Crimson Coder

    This is very strange. Here’s the syntax I assume made it choke:

    It was the from line of the query.

    FROM ( $wpdb->table_name )

    Took the parenthesis off, as they’re not really needed when only selecting from 1 table, and it’s fine.

    Strange right there.

    I can email you more explicit info if you need/want it.

  • Luke
    • The Crimson Coder

    Sent. I will note that it appears to be the parenthesis on the FROM line which is the culprit.

    The original problem I notes a couple days ago had the same thing. It should have, since it’s mysql5 and that particular query was selecting from multiple tables in the FROM line.

  • shadi
    • New Recruit

    Am try to install Multi-DB package using 2 DB-Servers, and distribute WPMU-DB into 4069 DB.

    2048 in each DB-Server, but i get this error.

    “No WPMU site defined on this host. If you are the owner of this site, please check Debugging WPMU for further assistance.”


    | This is my configuration code. |


    add_dc_ip(‘196.150.100.’, ‘dc1’:wink:;

    add_db_server(‘global’, ‘master’, 1, 1,’72.50.100.1′,’localhost’, ‘wpmu_global’, ‘user’, ‘pass’:wink:;

    add_db_server(‘000’, ‘dc1′, 1, 1,’196.150.100.10′,’196.150.100.10’, ‘wpmu_1’, ‘user’, ‘pass’:wink:;

    add_db_server(7ff’, ‘dc1′, 1, 1,’196.150.100.10′,’196.150.100.10’, ‘wpmu_7ff’, ‘user’, ‘pass’:wink:;

    add_db_server(‘800’, ‘dc1′, 1, 0,’196.150.100.12′,’196.150.100.12’, ‘wpmu_800’, ‘user’, ‘pass’:wink:;

    add_db_server(‘fff’, ‘dc1′, 1, 0,’196.150.100.12′,’196.150.100.12’, ‘wpmu_fff’, ‘user’, ‘pass’:wink:;

    Any Help,…

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.