Hi, Bill, and thanks for the reply.
Bill Karwin wrote:
Quote:
Randy wrote:
Quote:
>So, here's the problem: what I want to do is a filtered
>import from the central database to the new client database,
>filtering out all other data except for the individual client's
>data.
>
What would such a program do, besides write a SQL query to do it? ;-)
Yeah, I kinda' figured that :^). OTOH, I was hoping that there was
a GUI tool out there that just lets you click on and select what you
wanted, generating the SQL on the fly, so to speak :^). An in-house
program we use (called NaviCat) is a MySQL admin tool, and it does
offer various switches when dealing with imports/exports; however,
the program skipped class when it came to being able to filter on
import/export. (Either that, or I haven't found it in the manual yet.)
If I had to guess, there is a program out there that does this. OTOH,
it prolly cost an arm and a leg. Throughout the years, I've noticed
that the "Okay. Here's the simple GUI tool to do this because you're
frickin' lazy" programs are _expensive_! :^). BTW, "the powers that
be" here like GUI tools, so that's what I'm trying to find, thus the
original question.
Quote:
You can use "databasename.tablename" specifiers in MySQL queries. So
you can select from the central database and insert into the
client-specific database in one statement, as long as both databases
reside on the same server instance.
That's the way things are set up, Bill. Kewlness.
Quote:
For example:
>
CREATE TABLE client1database.tablename
LIKE centraldatabase.tablename;
>
This creates a table in the "client1database" of identical structure to
the table in the "centaldatabase". But I don't think it creates foreign
key constraints correctly, it just creates them as indexed columns. You
may have to re-declare foreign keys yourself using ALTER TABLE. Or
maybe it does work if you recreate the referenced tables first.
Okay. I'll give this a shot and see what gives.
Quote:
The copy data from the central database to the destination database:
>
INSERT INTO client1database.tablename
(col1, col2, col3, etc.)
SELECT col1, col2, col3, etc.
FROM centraldatabase.tablename
WHERE colx = 'client1';
Well, the actual name of that particular key would be company_id :^).
Quote:
I'm assuming "colx = 'client1" is some hypothetical expression you can
use to identify data that belongs to the individual client. After you
have moved the client's data and verified that it is present in the
client-specific database, you can delete it from the central database:
>
DELETE FROM centraldatabase.tablename
WHERE colx = 'client1';
Okay, but I'll make sure I do a backup before excuting that particular
line of code. Centraldatabase is _ALL_ of our customers data,
unfortunately. It is backed up, tho! :^)
Quote:
After you have deleted all the clients' data from the central database,
be sure to do an OPTIMIZE TABLE tablename, which will defragment and
reclaim the space used by deleted rows, and rebuild index structures to
be efficient for the new, reduced set of data.
Actually, I read the MySQL on-line docs, and I did an OPTIMIZE TABLE
tablename, but the rows are so numerous in all the tables that queries
were still taking a minute or two to complete. And this is when I came
up with the "single database per client and let MySQL handle it"
solution :^).
Actually, this model would seem to be perfect, because:
1) It would be _MUCH_ faster. :^)
2) Easy to replicate off site.
3) Easy to transfer a client database to another server.
4) Make clients data more readily available, especially if a client
program decides to corrupt the database, for some unknown, screw-up
reason :^). That is, if a client program corrupts their database,
they only corrupt _their_ data -- not everyone else's data. All other
clients should cruise on as if nothing happened, one would think.
5) Much quicker on import/export via dumpfile, etc.
6) Easier to backup.
7) Muck easier to transfer over to a cluster, "five nines" system.
Hey, it's not quite MySQL Cluster, but it's a start :^).
Quote:
Note that if you use InnoDB and you want to reduce the physical size of
the tablespace file (typically "<datadir>/ibdata1"), deleting data and
OPTIMIZE TABLE won't do that. InnoDB will mark the space as free, and
use it for new data in the future, growing the file again only after the
free space has been filled. It shouldn't hurt anything to have a
tablespace file with lots of free space.
I'm not familiar with InnoDB, Bill. BTW, I should mention that I'm a
neophyte in many areas of MySQL, although I do have experience with
Oracle, Visual Fox Pro, MS Access, and limited experience with the
PHP/MySQL combo for personal web-page development. OTOH, I do understand
a bit about software engineering, SCADA, embedded control and the like,
and I "REALLY FRICKIN' MISS" assembly progin'. Damn OOP dorks :^) :^).
(Just pickin', folks. I love OOD -- but I do miss assembly!) :^)
Quote:
But if you want to shrink the tablespace file immediately, you must do
the following:
1. Back up all InnoDB tables with mysqldump
2. Stop the MySQL Server
3. Physically remove the InnoDB tablespace file
4. Restart the MySQL server
5. Restore the backed-up tables by running the dump files through the
mysql client.
Okay. Thanks for the info. I'll make sure that I save this info for
future reference. Thanks!
Quote:
If you run a 24/7 operation, taking the MySQL server down might not be
practical. So you'll have to live with a big, partially-empty
tablespace file for a while.
Yep. 24/7/365. This is the main reason I'm talking up MySQL Cluster
here at work. After I read about "five nines" availability, I knew
that our customers will eventually demand this.
Quote:
That shouldn't hurt anything, though some people will poke their head
into the database and shout, "Hello! Echo!"
to hear their voice come back at them. ;-)
Well, this is the oil biz we're talking about, so it'd be more like
shouting "Hello World!" down the well head, and if you're not lucky,
you might start a blowout from too much acoustic resonance or something.
:^)
Quote:
But do make sure to do the OPTIMIZE TABLE on each table, which will make
the tables more efficient.
Did it the other day. Helped a bit, but not too much. Oh, well.
It's not like I didn't try or something :^).
Later, Bill, and thanks a ton, dewd!
Randy
--
Randall Jouett
Amateur/Ham Radio: AB5NI
I eat spaghetti code out of a bit bucket while sitting at a hash table!
Once someone offered salt, but I said, "I don't do encryption!"