Reputation: 979
Out of curiosity, say you have a huge MySQL database full of user information and it is now full. How would you run the same MySQL database off of the same server and another server with more storage space?
Upvotes: 4
Views: 24777
Reputation: 29769
If the problem is just a matter of storage space, then the simplest solution is to transfer the database to another system with more capacity.
Another solution could be adding a disk to the same system, and
The above files can be moved to a different hard drive (they might need to be symlink'd from their original location).
However, a truely widely scalable solution is a cluster of databases, like MySQL cluster.
You may also want to follow this question, in which this very problem is currently being addressed in a real environment.
[Edit] Detailed description:
The below information is valid on a Linux server only. It may be possible under Windows, but I have no idea. Running a MySQL database on Windows is probably not a good idea in a large scale environment anyways.
The three options rely on the same principle:
The InnoDB engine allows to spread the tablespace across many files. The configuration option to tweak (in my.cnf
) is innodb_data_file_path
. Example:
innodb_data_file_path=/mnt/hard_disk1/ibdata:50G;/mnt/hard_disk2/ibdata:200G;
... instructs MySQL to create /mnt/hard_disk1/ibdata1
, a 50GB file, as well as a 200GB file in /mnt/hard_disk2/ibdata2
.
I personnally dislike this feature because MySQL won't use the second file at all until the first one is full, which does not allow for fine tuning. The good side is you just need to edit your configuration file and restart the server. That's it.
The innodb_file_per_table
option, as the name suggests, instructs MySQL to create one separate file for each new table. "New table" means existing tables will not be impacted after changing the setup. To circumvent that, one can dump, delete, and recreate the table(s) to be "extracted" from the shared tablespace.
These files are [datadir]/[database]/[table].ibd
, where [datadir]
is defined by the datadir
option, and [database]
is the name of the database, and [table]
is the table name.
These files can be moved around just like the MyISAM tables (see next option).
For each MyISAM table, MySQL create three files named [datadir]/[database]/[table].[type]
, where [datadir]
is defined by the datadir
option, [database]
is the name of the database, and [table]
is the table name.
[type]
will be frm
for the table description (structure), MYD
for the data, MYI
for indexes.
Now, regarding options 2. and 3., you notice that all files are roughly located in the same directory, or at least share a parent directory. To actually store them on a new hard disk, there are two options.
1) To move a whole database:
database
directory to another name of your liking, say backup
datadir
/databse
backup
into datadir
/databse
MySQL resumes as if nothing ever happened.
2) To move individual tables:
MySQL resumes in a blissful ignorance.
Upvotes: 5
Reputation: 4886
as I see, the best solution will be to move the database in to a new server with higher capacity and restore the current database there. The current server lacks critical resources such as disk space and memory, therefore critically hamper the performance of the database.
further reading
after the migration, its a matter of changing the applicable data source files for any referring applications that use the same database.
Upvotes: 0