{"id":27,"date":"2010-02-05T21:31:51","date_gmt":"2010-02-05T18:31:51","guid":{"rendered":"http:\/\/meekconsulting.com\/?p=27"},"modified":"2010-02-05T21:31:51","modified_gmt":"2010-02-05T18:31:51","slug":"separating-storage-of-mysql-database-files","status":"publish","type":"post","link":"https:\/\/meekconsulting.com\/?p=27","title":{"rendered":"Separating storage of mysql database files"},"content":{"rendered":"<p>We often have very large databases we want to create in mysql.<\/p>\n<p>If we don\u2019t have enough space in the \/var\/lib\/mysql partition it is handy to be able to specify that a specific database be stored on another drive.<\/p>\n<p>This can fairly easily be done by using innodb_file_per_table parameter in your my.cnf and using symbolic links.\u00a0 The only tricky part is getting it to work under SELinux.\u00a0 ( Don\u2019t turn off SELINUX like other people say )\u00a0 just follow these instructions to get it to allow what you want.<\/p>\n<p>Steps to add new database that will use external storage:<\/p>\n<p>Create the database using:<\/p>\n<blockquote><p>mysqladmin -uroot -p  [pw] create newdbname<\/p>\n<p>Shutdown mysql<\/p>\n<p>\/etc\/init.d\/mysqld stop<\/p><\/blockquote>\n<p>Edit \/etc\/my.cnf\u00a0 adding line for innodb_file_per_table under the mysqld section<\/p>\n<blockquote><p>[mysqld]<\/p>\n<p>innodb_file_per_table<\/p><\/blockquote>\n<p>While db is shut down \u2014 move the directory for the new database to a partition with space.<\/p>\n<blockquote><p>mv \/var\/lib\/mysql\/newdbname \/bigpartition\/mysql\/newdbname<\/p><\/blockquote>\n<p>Create a symbolic link to the new location ( mysql looks only in \/var\/lib\/mysql for databases on startup)<\/p>\n<blockquote><p>cd \/var\/lib\/mysql<\/p>\n<p>ln -s \/bigpartition\/mysql\/newdbname newdbname<\/p>\n<p>ls -l \/bigpartition\/mysql\/newdbname<\/p><\/blockquote>\n<p>Fix the context on the newly created directories or you the database will not be visible when mysql restarts ( SELinux will prohibit mysql from using files in these directories )<\/p>\n<blockquote><p>chcon -c -t mysqld_db_t \/bigpartition\/mysql<\/p>\n<p>chcon -c -t mysqld_db_t \/bigpartition\/mysql\/newdbname<\/p><\/blockquote>\n<p>Re-start the MYSQL database<\/p>\n<blockquote><p>\/etc\/init.d\/mysql start<\/p><\/blockquote>\n<p>Restore your database dump or create new tables.\u00a0 The command I use is:<\/p>\n<blockquote><p>nohup time gunzip < backup.dmp.gz | mysql -uroot -p[dbpw] newdbname > restore.err 2>&1 &<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>We often have very large databases we want to create in mysql. If we don\u2019t have enough space in the \/var\/lib\/mysql partition it is handy to be able to specify that a specific database be stored on another drive. This &hellip; <a href=\"https:\/\/meekconsulting.com\/?p=27\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/27"}],"collection":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":1,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":28,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/28"}],"wp:attachment":[{"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meekconsulting.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}