{"id":60,"date":"2014-02-13T00:35:02","date_gmt":"2014-02-13T00:35:02","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=41"},"modified":"2014-02-13T00:35:02","modified_gmt":"2014-02-13T00:35:02","slug":"migrate-mysql-from-slaved-drive","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2014\/02\/13\/migrate-mysql-from-slaved-drive\/","title":{"rendered":"Migrate MySQL from Slaved Drive"},"content":{"rendered":"<p>Migrate MySQL from Slaved Drive<\/p>\n<p>1. Mount the slave drive.  We\u2019ll assume you mounted it at \/media\/slave<\/p>\n<p>Find the drive:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# fdisk -l\nDisk \/dev\/sda: 1000.2 GB, 1000204886016 bytes\n255 heads, 63 sectors\/track, 121601 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x000374d4\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sda1   *           1          64      512000   83  Linux\nPartition 1 does not end on cylinder boundary.\n\/dev\/sda2              64         587     4194304   82  Linux swap \/ Solaris\nPartition 2 does not end on cylinder boundary.\n\/dev\/sda3             587      121602   972054528   83  Linux\n\nDisk \/dev\/sdb: 1000.2 GB, 1000204886016 bytes\n255 heads, 63 sectors\/track, 121601 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x00000000\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sdb1   *           1          62      497983+  83  Linux\n\/dev\/sdb2              64         584     4184932+  82  Linux swap \/ Solaris\n\/dev\/sdb3             585      121598   972044955   82  Linux swap \/ Solaris\n\n<\/pre>\n<p>sdb is the drive &#8211; the slaved drive after the reinstall<br \/>\nCheck to see if it is ext3 or ext4<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# blkid \/dev\/sdb3\n\/dev\/sdb3: UUID=&quot;52721885-a9af-45e9-89f5-5f26ffca55dd&quot; TYPE=&quot;ext3&quot;\n<\/pre>\n<p>Mount according to ext3 or ext4<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nmount -t ext3 \/dev\/sdb3 \/media\/slave\n<\/pre>\n<p>Add to fstab<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# nano \/etc\/fstab\n\/dev\/sdb3   \/media\/slave   ext3   default 0   1 \n<\/pre>\n<p>2. Edit the MySQL config file to point to the slave\u2019s mysql databases<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnano \/etc\/my.cnf\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# datadir = \/var\/lib\/mysql\ndatadir = \/media\/slave\/var\/lib\/mysql\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nservice mysqld restart\n\n<\/pre>\n<p>3. Export the required database<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nmysqldump -u root -p&#x5B;root_password] &#x5B;database_name] &gt; dumpfilename.sql\n\n<\/pre>\n<p>for plesk:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nmysqldump -u admin -p`cat \/etc\/psa\/.psa.shadow` &#x5B;database_name] &gt; dumpfilename.sql\n\n<\/pre>\n<p>4. Reset the Mysql path and import the file<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nnano \/etc\/my.cnf\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\ndatadir = \/var\/lib\/mysql\n# datadir = \/media\/slave\/var\/lib\/mysql\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nservice mysqld restart\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nmysql -u root -p&#x5B;root_password] &#x5B;database_name] &lt; dumpfilename.sql\n\n&amp;#91;\/bash&amp;#93;\n\nPlesk:\n&amp;#91;bash&amp;#93;\n\nmysql -u admin -p`cat \/etc\/psa\/.psa.shadow` &amp;#91;database_name&amp;#93; &lt; dumpfilename.sql\n\n&amp;#91;\/bash&amp;#93;\n\nHotkey for Plesk specifically mounted to \/olddrive\/:\n\nBefore migrating, make sure the database you are migrating has already been created in Plesk with the correct username and password.\n\n1. Log onto your server as root using ssh.\n\n2. Edit the mysql config file to use the slave drive\nnano \/etc\/my.cnf\n\n3. Comment out the current path, add your slaved drive\u2019s path and save the file\n&amp;#91;bash&amp;#93;\n\n# datadir = \/var\/lib\/mysql\ndatadir = \/olddrive\/var\/lib\/mysql\n\n\n&amp;#91;\/bash&amp;#93;\n\n(save the file using &lt;ctrl&gt;&lt;o&gt; then &lt;ctrl&gt;&lt;x&gt; to exit.\n\n4. Restart mysql to load the new settings\n&#x5B;bash]\n\nservice mysqld restart\n\n<\/pre>\n<p>5. Create a dump file of the desired database<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nmysqldump -u admin -p`cat \/etc\/psa\/.psa.shadow` &#x5B;database_name] &gt; \/tmp\/database_name.sql\n\n<\/pre>\n<p>(Repeat this step for all databases that need to be imported)<\/p>\n<p>6. Repeat step 2-4 and reset the original setting<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\ndatadir = \/var\/lib\/mysql\n# datadir = \/olddrive\/var\/lib\/mysql\n\n<\/pre>\n<p>7. Import the database<\/p>\n<p>mysql -u admin -p`cat \/etc\/psa\/.psa.shadow` [database_name] < \/tmp\/database_name.sql\n\n[\/bash]\n\n(Repeat this step for all .sql files created in step 5)\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Migrate MySQL from Slaved Drive 1. Mount the slave drive. We\u2019ll assume you mounted it at \/media\/slave Find the drive: # fdisk -l Disk \/dev\/sda: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors\/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical\/physical): 512 bytes \/ 512 bytes I\/O size &#8230; <a title=\"Migrate MySQL from Slaved Drive\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2014\/02\/13\/migrate-mysql-from-slaved-drive\/\" aria-label=\"Read more about Migrate MySQL from Slaved Drive\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}