{"id":527,"date":"2014-04-22T15:28:32","date_gmt":"2014-04-22T14:28:32","guid":{"rendered":"http:\/\/it.tuxie.eu\/?p=527"},"modified":"2014-04-22T15:28:32","modified_gmt":"2014-04-22T14:28:32","slug":"change-data-directory-mariadb-10-0-x","status":"publish","type":"post","link":"http:\/\/it.tuxie.eu\/?p=527","title":{"rendered":"Change data directory &#8211; MariaDB 10.0.x"},"content":{"rendered":"<p>One of most valuable thing is good documentation &#8211; for common database actions. I didn\u00b4t find any well documented step-by-step guide to change data directory in MariaDB, Debian environment. <strong>Please be aware that this one guide is not perfect and some hidden traps can be found there<\/strong>. I have a dream to have some scripts for these basic database tasks&#8230;. \ud83d\ude42<\/p>\n<p><!--more--><\/p>\n<p>First I check current datadir:<\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">MariaDB [(none)]&gt; <span style=\"color: #ff0000;\"><strong>show variables where variable_name like &#8218;datadir&#8216;;<\/strong><\/span><\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">| Variable_name | Value |<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">| datadir | \/var\/lib\/mysql\/ |<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">1 row in set (0.00 sec)<\/span><\/p>\n<p>Now I will create new directory target for storing data &#8211; \/MYDATA:<\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~# <span style=\"color: #ff0000;\"><strong>mkdir \/MYDATA<\/strong><\/span><\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~# <span style=\"color: #ff0000;\"><strong>id mysql<\/strong><\/span><\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">uid=115(mysql) gid=124(mysql) groups=124(mysql)<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~# <span style=\"color: #ff0000;\"><strong>chown mysql:mysql \/MYDATA<\/strong><\/span><\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~#<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~# <span style=\"color: #ff0000;\"><strong>cp -R -p \/var\/lib\/mysql \/MYDATA<\/strong><\/span><\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~# <span style=\"color: #ff0000;\"><strong>chmod 775 -R \/MYDATA<\/strong><\/span><\/span><\/p>\n<p>Now it\u00b4s time to adjust \/etc\/mysql\/my.cnf &#8211; I just changed datadir variable in [mysqld] section.<\/p>\n<p>Now the mysql_install_db re-initialization:<\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~# <span style=\"color: #ff0000;\"><strong>mysql_install_db<\/strong> <\/span><\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">Installing MariaDB\/MySQL system tables in &#8218;\/MYDATA&#8216; &#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: The InnoDB memory heap is disabled<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Compressed tables use zlib 1.2.7<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Using Linux native AIO<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Not using CPU crc32 instructions<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Initializing buffer pool, size = 256.0M<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Completed initialization of buffer pool<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Highest supported file format is Barracuda.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Log scan progressed past the checkpoint lsn 49463<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Database was not shutdown normally!<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Starting crash recovery.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Reading tablespace information from the .ibd files&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Restoring possible half-written data pages <\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: from the doublewrite buffer&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">InnoDB: Doing recovery: scanned up to log sequence number 1600737<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Starting an apply batch of log records to the database&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">InnoDB: Progress in percent: 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 <\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">InnoDB: Apply batch completed<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: 128 rollback segment(s) are active.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Waiting for purge to start<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] InnoDB: Percona XtraDB (http:\/\/www.percona.com) 5.6.15-63.0 started; log sequence number 1600737<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] Recovering after a crash using \/var\/log\/mysql\/mariadb-bin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] Starting crash recovery&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Note] Crash recovery finished.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:07 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table &#8218;mysql.gtid_slave_pos&#8216; doesn&#8217;t exist<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:09 [Note] InnoDB: FTS optimize thread exiting.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:09 [Note] InnoDB: Starting shutdown&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: Shutdown completed; log sequence number 1619188<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">OK<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">Filling help tables&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: The InnoDB memory heap is disabled<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: Compressed tables use zlib 1.2.7<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: Using Linux native AIO<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: Not using CPU crc32 instructions<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:10 [Note] InnoDB: Initializing buffer pool, size = 256.0M<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: Completed initialization of buffer pool<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: Highest supported file format is Barracuda.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: 128 rollback segment(s) are active.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: Waiting for purge to start<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: Percona XtraDB (http:\/\/www.percona.com) 5.6.15-63.0 started; log sequence number 1619188<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: FTS optimize thread exiting.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:11 [Note] InnoDB: Starting shutdown&#8230;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">140422 14:45:13 [Note] InnoDB: Shutdown completed; log sequence number 1619198<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">OK<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">To start mysqld at boot time you have to copy<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">support-files\/mysql.server to the right place for your system<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">To do so, start the server, then issue the following commands:<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">&#8218;\/usr\/bin\/mysqladmin&#8216; -u root password &#8218;new-password&#8216;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">&#8218;\/usr\/bin\/mysqladmin&#8216; -u root -h deb74 password &#8218;new-password&#8216;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">Alternatively you can run:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">&#8218;\/usr\/bin\/mysql_secure_installation&#8216;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">which will also give you the option of removing the test<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">databases and anonymous user created by default. This is<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">strongly recommended for production servers.<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">See the MariaDB Knowledgebase at http:\/\/mariadb.com\/kb or the<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">MySQL manual for more instructions.<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">You can start the MariaDB daemon with:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">cd &#8218;\/usr&#8216; ; \/usr\/bin\/mysqld_safe &#8211;datadir=&#8217;\/MYDATA&#8216;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">You can test the MariaDB daemon with mysql-test-run.pl<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">cd &#8218;\/usr\/mysql-test&#8216; ; perl mysql-test-run.pl<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">Please report any problems at http:\/\/mariadb.org\/jira<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">The latest information about MariaDB is available at http:\/\/mariadb.org\/.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">You can find additional information about the MySQL part at:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">http:\/\/dev.mysql.com<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">Support MariaDB development by buying support\/new features from<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">SkySQL Ab. You can contact us about this at sales@skysql.com.<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">Alternatively consider joining our community based development effort:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier; font-size: 12px;\">http:\/\/mariadb.com\/kb\/en\/contributing-to-the-mariadb-project\/<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier; font-size: 12px;\">root@deb74:~#<\/span><\/p>\n<p>Reboot is needed, service is started properly with newly added path.<\/p>\n<p>I really do have some unclear thoughts, whole process seems more complicated than it should be. Anyway it\u00b4s working for me till now&#8230;.<\/p>\n<p>Any comments appreciated! \ud83d\ude42<\/p>\n<p>-a-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of most valuable thing is good documentation &#8211; for common database actions. I didn\u00b4t find any well documented step-by-step guide to change data directory in MariaDB, Debian environment. Please be aware that this one guide is not perfect and &hellip; <a href=\"http:\/\/it.tuxie.eu\/?p=527\">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":[7,13],"tags":[],"_links":{"self":[{"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=\/wp\/v2\/posts\/527"}],"collection":[{"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=527"}],"version-history":[{"count":0,"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=\/wp\/v2\/posts\/527\/revisions"}],"wp:attachment":[{"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=527"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/it.tuxie.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}