mysql, store schema in other partition/file system? - mysql

All my databases are fairly small so it is no problem to use MariaDB on my laptop. But now I will have to work with a database that is too large for my harddisk.
I guess that when I edit my.cnf, it should be possible to use an alternative datadir. This would have the disadvantage that I have to change or edit my.cnf every time I want to select another schema.
What I would like to see is that I can use/select the schema on the external disk, only when that disk is mounted.
Is this possible? If not, what are the alternatives?
Ben

Huh? See the DATA DIRECTORY clause in CREATE TABLE. To give you more specifics, we need to know
What OS you are using.
What ENGINE the table is.
What version of MySQL or MariaDB you are using.
The value of innodb_file_per_table.

Related

MYSQL data on multiple drives

I have a MYSQL database on my SDA. It's mostly all one schema with "popular" tables in it. I want to store the less "popular" tables of the schema (which take up another 1TB or so) on my SDB partition.
What is the right way to do this? Do I need another MYSQL server running on that drive? Or can I simply set like DATA_DIRECTORY= or something? This is Ubuntu and MYSQL 5.7.38. Thank you for any help, it's much appreciated.
As of MySQL 8.0.21, the ability to specify the data directory per table has finally improved.
CREATE TABLE t1 (c1 INT PRIMARY KEY) DATA DIRECTORY = '/external/directory';
Read https://dev.mysql.com/doc/refman/8.0/en/innodb-create-table-external.html#innodb-create-table-external-data-directory for details.
In earlier versions of MySQL, you could use symbolic links. That is, the link still has to reside under the default data directory, but the link can point to a file on another physical device.
It was unreliable to use symbolic links for individual tables in this way, because OPTIMIZE TABLE or many forms of ALTER TABLE would recreate the file without the symbolic link, effectively moving it back to the primary storage device. To solve this, it was recommended to use a symbolic link for the schema subdirectory instead of individual tables.
To be honest, I've never found a case where I needed to use either of these techniques. Just keep it simple: one data directory on one filesystem, and don't put the data directory on the same device as the root filesystem. Make sure the data storage volume is large enough for all your data. Use software RAID if you need to use multiple devices to make one larger filesystem.

How can I use transparent data encryption with MySQL?

I want to enable Transparent Data encryption (TDE) on MySQL. I don't mind if the entire db is encrypted (as opposed to a few columns or rows or tables). I am using this for a study, so I am looking for something that is open and free. I found zNcrypt but it's a commercial product. They are essentially using eCryptfs which is open-source, but couldn't find a way to rightly configure it for MySQL.
Any pointers on using eCryptfs with MySQL or any other solution for enabling TDE with MySQL would be very helpful. Thanks!
I see this question is relatively old, but just in case:
eCryptfs can be considered a filesystem, so, you should just need to mount it, and then point your MySQL datadir to the mounted directory. The only drawback is that it doesn't seems to support O_DIRECT, but I don't think MySQL uses it, does it?

Can I move MySQL table to a second drive?

I am having I/O related performance problems that would be solved if a few relatively small tables were running on a SSD. I can't move the entire DB to SSD because it is much too large.
I thought this was possible (map specific tables to different drives) but a tech at my managed hosting company says that the entire DB needs to be in a single directory. Is this correct? If he's wrong, can someone point me somewhere with basic instructions on how this is done? Or even provide the instructions here?
When you create a MySQL table you can specify the data directory and index directory.
Have a look at http://dev.mysql.com/doc/refman/5.1/en/create-table.html
So, to answer your question, you could create a new table in the different directory and migrate your data there.

Populate MySQL timezone info from MySQL data set, not from system without restart

I'd like to populate the MySQL timezone tables with the database provided by MySQL. I am using a cloud DB and can't overwrite DB tables and restart the server.
Can someone help me understand how to load these files manually?
Rational
I loaded the tz tables from the OS, but the OS has a ton of timezone names. I'd like a more concise set of names that I can query for forms. I think the set provided by MySQL might be a better fit. No other apps are running on the database, thus timezone conflicts aren't an issue.
The database provided by mysql comes as a bunch of myISAM container files; I don't think you're going to be able to safely drop them into the mysql data base directory without bouncing your mysqld.
Do you own this mysqld, or are you one of many tenants in a vendor-owned system?
If you own it, you can load a subset of the /usr/share/zoneinfo time zones. A useful subset might be /usr/share/zoneinfo/posix.
If you're using the mysql.time_zone_name.Name to populate a pick list (a good use for it) you could select an appropriate subset of the admittedly enormous list of names,
or create some aliases right in that table.
I ended up loading the tables into a SQL server on my on local machine, then exporting insert statements and manually loading those onto the server for which I don't have direct control of. Not a glamors solution, it it appears to be the only reasonable way to go about it.

Mysql create database with new database location

Few months ago I have asked a question regarding how to change database location at runtime - I didn't get any solution for this problem yet.
I am needing to create more than 32,000 databases in MySQL. The default data location of MySQL data folder, after creating 32,000 database on that location, I want to change the data directory to other location. I am planning to do this through Java code.
But before that can anyone tell me if this is possible?
I am really needing to implement this as an requirement. Please help me out with this.
I am sorry If I am unclear anywhere in this description, but let me know if you all need any more information.
That sounds difficult. I don't understand why 32000 - is mysql refusing to create more databases than that? What error do you get? Seems arbitrary - maybe this is a config variable that can be changed?
A few possibilities. You could run more than one mysql server, each with a different data directory. I don't think it would help, but you might look into the NDB storage engine, it can handle tablespaces which just might let you store data in multiple locations.
You can create several partitions and join them using LVM (this is in Linux) and mount the partition to the DATADIR path. Also you can use soft links the the databases moved to other folders/partitions.
Unfortunately MySQL supports only one DATADIR but it seemed to me that InnoDB tables can be places to separate path. Could you check this?