{"id":4963,"date":"2019-05-12T21:39:32","date_gmt":"2019-05-12T21:39:32","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=4963"},"modified":"2019-05-12T21:39:32","modified_gmt":"2019-05-12T21:39:32","slug":"import-a-large-sql-dump-file-to-a-mysql-database-from-command-line","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2019\/05\/12\/import-a-large-sql-dump-file-to-a-mysql-database-from-command-line\/","title":{"rendered":"Import a large sql dump file to a MySQL database from command line"},"content":{"rendered":"<p>How to import a very large SQL dump file (6 Gb) to a MySQL database using windows command line. If you are using linux it is the same. The process is the following:<\/p>\n<p>Open a command prompt (or shell in Linux) with administrative privilleges<\/p>\n<p>Connect to a mysql instance using command line:<\/p>\n<p><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># mysql -h 192.168.1.1 --port=3306 -u root -p<\/pre>\n<p><\/p>\n<p>if you are in localhost you do not need host and port<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># mysql -u root -p\n\n<\/pre>\n<p>Or if plesk,<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># mysql -uadmin -p`cat \/etc\/psa\/.psa.shadow`\n<\/pre>\n<p>You are now in mysql shell. Set network buffer length to a large byte number. The default value may throw errors for such large data files<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mysql&amp;gt; set global net_buffer_length=1000000;\n\n<\/pre>\n<p>Set maximum allowed packet size to a large byte number.The default value may throw errors for such large data files.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mysql&amp;gt; set global max_allowed_packet=1000000000;\n<\/pre>\n<p>Disable foreign key checking to avoid delays,errors and unwanted behaviour<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mysql&amp;gt; SET foreign_key_checks = 0;\nmysql&amp;gt; SET UNIQUE_CHECKS = 0;\nmysql&amp;gt; SET AUTOCOMMIT = 0;\n<\/pre>\n<p>Import your sql dump file<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mysql&amp;gt; use db_name;\nmysql&amp;gt; source backup-file.sql;\n<\/pre>\n<p>Remember to enable foreign key checks when procedure is complete!<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"> mysql&amp;gt; SET foreign_key_checks = 1;\n mysql&amp;gt; SET UNIQUE_CHECKS = 1;\n mysql&amp;gt; SET AUTOCOMMIT = 1;\n<\/pre>\n<p>If you are in Linux you can create a Bash script which will do the dirty job and write to stdout start and end time of import:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">  #!\/bin\/sh \n\n  # store start date to a variable\n  imeron=`date`\n\n  echo &quot;Import started: OK&quot;\n  dumpfile=&quot;\/home\/bob\/bobiras.sql&quot;\n\n  ddl=&quot;set names utf8; &quot;\n  ddl=&quot;$ddl set global net_buffer_length=1000000;&quot;\n  ddl=&quot;$ddl set global max_allowed_packet=1000000000; &quot;\n  ddl=&quot;$ddl SET foreign_key_checks = 0; &quot;\n  ddl=&quot;$ddl SET UNIQUE_CHECKS = 0; &quot;\n  ddl=&quot;$ddl SET AUTOCOMMIT = 0; &quot;\n  # if your dump file does not create a database, select one\n  ddl=&quot;$ddl USE jetdb; &quot;\n  ddl=&quot;$ddl source $dumpfile; &quot;\n  ddl=&quot;$ddl SET foreign_key_checks = 1; &quot;\n  ddl=&quot;$ddl SET UNIQUE_CHECKS = 1; &quot;\n  ddl=&quot;$ddl SET AUTOCOMMIT = 1; &quot;\n  ddl=&quot;$ddl COMMIT ; &quot;\n\n  echo &quot;Import started: OK&quot;\n\n  time mysql -h 127.0.0.1 -u root -proot -e &quot;$ddl&quot;\n\n  # store end date to a variable\n  imeron2=`date`\n\n  echo &quot;Start import:$imeron&quot;\n  echo &quot;End import:$imeron2&quot;\n\n<\/pre>\n<p>Other solutions:<br \/>\nBig Dump<br \/>\nhttp:\/\/www.ozerov.de\/bigdump\/ seems good<\/p>\n<p>Split Files<br \/>\nhttp:\/\/www.rusiczki.net\/2007\/01\/24\/sql-dump-file-splitter\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to import a very large SQL dump file (6 Gb) to a MySQL database using windows command line. If you are using linux it is the same. The process is the following: Open a command prompt (or shell in Linux) with administrative privilleges Connect to a mysql instance using command line: # mysql -h &#8230; <a title=\"Import a large sql dump file to a MySQL database from command line\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2019\/05\/12\/import-a-large-sql-dump-file-to-a-mysql-database-from-command-line\/\" aria-label=\"Read more about Import a large sql dump file to a MySQL database from command line\">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-4963","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/4963","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=4963"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/4963\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=4963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=4963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=4963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}