backup-restore-mysql.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <!-- Always force latest IE rendering engine or request Chrome Frame -->
  6. <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <!-- Use title if it's in the page YAML frontmatter -->
  9. <title>Backup and Restore MySQL/MariaDB Databases</title>
  10. <link href="/dashboard/stylesheets/normalize.css" rel="stylesheet" type="text/css" /><link href="/dashboard/stylesheets/all.css" rel="stylesheet" type="text/css" />
  11. <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
  12. <script src="/dashboard/javascripts/modernizr.js" type="text/javascript"></script>
  13. <link href="/dashboard/images/favicon.png" rel="icon" type="image/png" />
  14. </head>
  15. <body class="docs docs_backup-restore-mysql">
  16. <div id="fb-root"></div>
  17. <script>(function(d, s, id) {
  18. var js, fjs = d.getElementsByTagName(s)[0];
  19. if (d.getElementById(id)) return;
  20. js = d.createElement(s); js.id = id;
  21. js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=277385395761685";
  22. fjs.parentNode.insertBefore(js, fjs);
  23. }(document, 'script', 'facebook-jssdk'));</script>
  24. <div class="contain-to-grid">
  25. <nav class="top-bar" data-topbar>
  26. <ul class="title-area">
  27. <li class="name">
  28. <h1><a href="/dashboard/index.html">Apache Friends</a></h1>
  29. </li>
  30. <li class="toggle-topbar menu-icon">
  31. <a href="#">
  32. <span>Menu</span>
  33. </a>
  34. </li>
  35. </ul>
  36. <section class="top-bar-section">
  37. <!-- Right Nav Section -->
  38. <ul class="right">
  39. <li class=""><a href="/applications.html">Applications</a></li>
  40. <li class=""><a href="/dashboard/faq.html">FAQs</a></li>
  41. <li class="active"><a href="/dashboard/howto.html">HOW-TO Guides</a></li>
  42. <li class=""><a target="_blank" href="/dashboard/phpinfo.php">PHPInfo</a></li>
  43. <li class=""><a href="/phpmyadmin/">phpMyAdmin</a></li>
  44. </ul>
  45. </section>
  46. </nav>
  47. </div>
  48. <div id="wrapper">
  49. <div class="hero">
  50. <div class="row">
  51. <div class="large-12 columns">
  52. <h1>Documentation</h1>
  53. </div>
  54. </div>
  55. </div>
  56. <div class="row">
  57. <div class="large-12 columns">
  58. <ul class="sub-nav">
  59. <li>
  60. <a class="pdf" target="_blank" href="/dashboard/docs/backup-restore-mysql.pdf"> Download PDF
  61. <span>backup-restore-mysql.pdf</span>
  62. </a> </li>
  63. </ul>
  64. <article class="asciidoctor">
  65. <aside>
  66. <h3>Contents</h3>
  67. <ol class="sections">
  68. <li><a href="/dashboard/docs/backup-restore-mysql.html#using_phpmyadmin">Using phpMyAdmin</a></li>
  69. <li><a href="/dashboard/docs/backup-restore-mysql.html#using_command_line_tools">Using Command-Line Tools</a></li>
  70. </ol>
  71. </aside>
  72. <h1>Backup and Restore MySQL/MariaDB Databases</h1>
  73. <div id="preamble">
  74. <div class="sectionbody">
  75. <div class="paragraph">
  76. <p>As you use XAMPP, you might find that you need to backup or restore a MySQL or MariaDB database. There are two easy ways to do this with XAMPP: using the browser-based phpMyAdmin tool or using MySQL/MariaDB&#8217;s command-line tools. This guide describes both options.</p>
  77. </div>
  78. <div class="paragraph">
  79. <p>This guide assumes that you already have a PHP application that uses a MySQL/MariaDB database deployed on XAMPP. The example application used in this guide is WordPress, although the steps outlined below will work for any application.</p>
  80. </div>
  81. <div class="admonitionblock tip">
  82. <table>
  83. <tr>
  84. <td class="icon">
  85. <i class="fa icon-tip" title="Tip"></i>
  86. </td>
  87. <td class="content">
  88. Remember that you can install WordPress quickly using the <a href="https://bitnami.com/stack/xampp#wordpress">Bitnami WordPress module for XAMPP</a>.
  89. </td>
  90. </tr>
  91. </table>
  92. </div>
  93. </div>
  94. </div>
  95. <div class="sect1">
  96. <h2 id="_using_phpmyadmin">Using phpMyAdmin</h2>
  97. <div class="sectionbody">
  98. <div class="paragraph">
  99. <p>XAMPP includes <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, an open-source, browser-based tool for managing MySQL/MariaDB database servers. To backup a MySQL/MariaDB database using phpMyAdmin, follow these steps:</p>
  100. </div>
  101. <div class="olist arabic">
  102. <ol class="arabic">
  103. <li>
  104. <p>Browse to <a href="http://localhost/phpMyAdmin" class="bare">http://localhost/phpMyAdmin</a> or <a href="http://127.0.0.1/phpMyAdmin" class="bare">http://127.0.0.1/phpMyAdmin</a>. If required, log in using your database access credentials. On a fresh XAMPP installation without any changes, you can log in as <em>root</em> with a blank password.</p>
  105. </li>
  106. <li>
  107. <p>Select the database to be backed up from the list in the left navigation pane. In this case, we&#8217;re backing up the WordPress database, which is named <em>bitnami_wordpress</em>.</p>
  108. <div class="imageblock">
  109. <div class="content">
  110. <img src="./images/backup-restore-mysql/image1.png" alt="image1">
  111. </div>
  112. </div>
  113. </li>
  114. <li>
  115. <p>Select the "Export" command in the top navigation bar.</p>
  116. </li>
  117. <li>
  118. <p>On the resulting page, select "Quick" as the export method and "SQL" as the output format. Click "Go" to proceed.</p>
  119. <div class="imageblock">
  120. <div class="content">
  121. <img src="./images/backup-restore-mysql/image2.png" alt="image2">
  122. </div>
  123. </div>
  124. </li>
  125. </ol>
  126. </div>
  127. <div class="paragraph">
  128. <p>phpMyAdmin will export the database to a text file as a series of SQL statements. Once done, the browser will prompt you to download it to the desktop. This text file is your backup, so store it safely!</p>
  129. </div>
  130. <div class="imageblock">
  131. <div class="content">
  132. <img src="./images/backup-restore-mysql/image3.png" alt="image3">
  133. </div>
  134. </div>
  135. <div class="paragraph">
  136. <p>At a later point, you may wish to restore the database. To restore the data to a fresh MySQL/MariaDB database using phpMyAdmin, follow these steps:</p>
  137. </div>
  138. <div class="olist arabic">
  139. <ol class="arabic">
  140. <li>
  141. <p>Browse to <a href="http://localhost/phpMyAdmin" class="bare">http://localhost/phpMyAdmin</a> or <a href="http://127.0.0.1/phpMyAdmin" class="bare">http://127.0.0.1/phpMyAdmin</a>. If required, log in using your database access credentials.</p>
  142. </li>
  143. <li>
  144. <p>Select the "New" command in the left navigation pane.</p>
  145. <div class="imageblock">
  146. <div class="content">
  147. <img src="./images/backup-restore-mysql/image4.png" alt="image4">
  148. </div>
  149. </div>
  150. </li>
  151. <li>
  152. <p>On the resulting page, enter a name for the new database (in this case, <em>myblog</em>). Select the collation "utf8_general_ci". Click "Create" to create the database.</p>
  153. <div class="imageblock">
  154. <div class="content">
  155. <img src="./images/backup-restore-mysql/image5.png" alt="image5">
  156. </div>
  157. </div>
  158. <div class="paragraph">
  159. <p>Once the database has been created, it will appear in the left navigation pane.</p>
  160. </div>
  161. <div class="imageblock">
  162. <div class="content">
  163. <img src="./images/backup-restore-mysql/image6.png" alt="image6">
  164. </div>
  165. </div>
  166. </li>
  167. <li>
  168. <p>Select the new database from the left navigation pane. In the resulting page, select the "Import" command in the top navigation bar.</p>
  169. </li>
  170. <li>
  171. <p>Click the "Browse&#8230;&#8203;" button and select the backup file created earlier. Click "Go" to proceed.</p>
  172. <div class="imageblock">
  173. <div class="content">
  174. <img src="./images/backup-restore-mysql/image7.png" alt="image7">
  175. </div>
  176. </div>
  177. <div class="paragraph">
  178. <p>phpMyAdmin will import the data from the backup file. Once complete, you will see a screen indicating the status of the import.</p>
  179. </div>
  180. <div class="imageblock">
  181. <div class="content">
  182. <img src="./images/backup-restore-mysql/image8.png" alt="image8">
  183. </div>
  184. </div>
  185. </li>
  186. </ol>
  187. </div>
  188. <div class="paragraph">
  189. <p>If you browse the contents of the database, you should now see your original data.</p>
  190. </div>
  191. <div class="imageblock">
  192. <div class="content">
  193. <img src="./images/backup-restore-mysql/image9.png" alt="image9">
  194. </div>
  195. </div>
  196. <div class="paragraph">
  197. <p>You should now update your application&#8217;s configuration and point it to your newly-created database. For example, with the Bitnami WordPress module, you will need to edit the <em>wp-config.php</em> file in the <em>apps\wordpress\htdocs\</em> subdirectory of your XAMPP installation directory. Within this file, you will need to update the <em>DB_NAME</em> constant to use the new database name.</p>
  198. </div>
  199. <div class="imageblock">
  200. <div class="content">
  201. <img src="./images/backup-restore-mysql/image10.png" alt="image10">
  202. </div>
  203. </div>
  204. <div class="admonitionblock note">
  205. <table>
  206. <tr>
  207. <td class="icon">
  208. <i class="fa icon-note" title="Note"></i>
  209. </td>
  210. <td class="content">
  211. By default, PHP (and therefore phpMyAdmin) is configured to only accept uploads up to 2 MB in size. If your database is larger than this, you need to modify the PHP configuration file to accept a larger upload size. To do this, edit the <em>php.ini</em> file in the <em>php\</em> subdirectory of your XAMPP installation directory and increase the values of the <em>post_max_size</em> and <em>upload_max_filesize</em> variables. Save your changes and restart Apache for the changes to take effect.
  212. </td>
  213. </tr>
  214. </table>
  215. </div>
  216. </div>
  217. </div>
  218. <div class="sect1">
  219. <h2 id="_using_command_line_tools">Using Command-Line Tools</h2>
  220. <div class="sectionbody">
  221. <div class="paragraph">
  222. <p>MySQL and MariaDB include two command-line tools that you can use to quickly backup and restore databases. The <em>mysqldump</em> tool is used to export the contents of a database to a text file, while the <em>mysql</em> client can be used to import data from a text file into a MySQL/MariaDB database.</p>
  223. </div>
  224. <div class="paragraph">
  225. <p>To backup a MySQL/MariaDB database from the command line, follow these steps:</p>
  226. </div>
  227. <div class="olist arabic">
  228. <ol class="arabic">
  229. <li>
  230. <p>Launch a new Windows command shell using the "Shell" button in the XAMPP control panel.</p>
  231. </li>
  232. <li>
  233. <p>Use the command below to export the contents of the selected database. In this example, we&#8217;re backing up the WordPress database, which is named <em>bitnami_wordpress</em>, to a file named <em>bitnami_wordpress.sql</em>. This text file is your backup, so store it safely!</p>
  234. <div class="literalblock">
  235. <div class="content">
  236. <pre>mysqldump --user=root --password="" bitnami_wordpress &gt; bitnami_wordpress.sql</pre>
  237. </div>
  238. </div>
  239. <div class="imageblock">
  240. <div class="content">
  241. <img src="./images/backup-restore-mysql/image11.png" alt="image11">
  242. </div>
  243. </div>
  244. </li>
  245. </ol>
  246. </div>
  247. <div class="paragraph">
  248. <p>At a later point, you may wish to restore the database. To restore the data to a fresh MySQL/MariaDB database from the command line, follow these steps:</p>
  249. </div>
  250. <div class="olist arabic">
  251. <ol class="arabic">
  252. <li>
  253. <p>Launch a new Windows command shell using the "Shell" button in the XAMPP control panel.</p>
  254. </li>
  255. <li>
  256. <p>Use the <em>mysql</em> client to create a new, empty database to hold your data. In this example, the new database is named <em>myblog</em>.</p>
  257. <div class="literalblock">
  258. <div class="content">
  259. <pre>mysql --user=root --password="" -e "CREATE DATABASE myblog"</pre>
  260. </div>
  261. </div>
  262. <div class="paragraph">
  263. <p>Remember to use the correct database access credentials in the command. On a fresh XAMPP installation without any changes, you can usually log in as root with a blank password.</p>
  264. </div>
  265. </li>
  266. <li>
  267. <p>Use the <em>mysql</em> client to import the contents of the backup file into the new database.</p>
  268. <div class="literalblock">
  269. <div class="content">
  270. <pre>mysql --user=root --password="" --database=myblog &lt; bitnami_wordpress.sql</pre>
  271. </div>
  272. </div>
  273. <div class="paragraph">
  274. <p>The command-line client will now import the data from the backup file.</p>
  275. </div>
  276. <div class="imageblock">
  277. <div class="content">
  278. <img src="./images/backup-restore-mysql/image12.png" alt="image12">
  279. </div>
  280. </div>
  281. </li>
  282. </ol>
  283. </div>
  284. <div class="paragraph">
  285. <p>If you browse the contents of the database, you should now see your original data.</p>
  286. </div>
  287. <div class="imageblock">
  288. <div class="content">
  289. <img src="./images/backup-restore-mysql/image13.png" alt="image13">
  290. </div>
  291. </div>
  292. <div class="paragraph">
  293. <p>You should now update your application&#8217;s configuration and point it to your newly-created database. For example, with the Bitnami WordPress module, you will need to edit the <em>wp-config.php</em> file in the <em>apps\wordpress\htdocs\</em> subdirectory of your XAMPP installation directory. Within this file, you will need to update the <em>DB_NAME</em> constant to use the new database name.</p>
  294. </div>
  295. <div class="imageblock">
  296. <div class="content">
  297. <img src="./images/backup-restore-mysql/image14.png" alt="image14">
  298. </div>
  299. </div>
  300. </div>
  301. </div>
  302. </article>
  303. </div>
  304. </div>
  305. </div>
  306. <footer>
  307. <div class="row">
  308. <div class="large-12 columns">
  309. <div class="row">
  310. <div class="large-8 columns">
  311. <ul class="social">
  312. <li class="twitter"><a href="https://twitter.com/apachefriends">Follow us on Twitter</a></li>
  313. <li class="facebook"><a href="https://www.facebook.com/we.are.xampp">Like us on Facebook</a></li>
  314. <li class="google"><a href="https://plus.google.com/+xampp/posts">Add us to your G+ Circles</a></li>
  315. </ul>
  316. <ul class="inline-list">
  317. <li><a href="https://www.apachefriends.org/blog.html">Blog</a></li>
  318. <li><a href="https://www.apachefriends.org/privacy_policy.html">Privacy Policy</a></li>
  319. <li>
  320. <a target="_blank" href="http://www.fastly.com/"> CDN provided by
  321. <img width="48" data-2x="/dashboard/images/fastly-logo@2x.png" src="/dashboard/images/fastly-logo.png" />
  322. </a> </li>
  323. </ul>
  324. </div>
  325. <div class="large-4 columns">
  326. <p class="text-right">Copyright (c) 2017, Apache Friends</p>
  327. </div>
  328. </div>
  329. </div>
  330. </div>
  331. </footer>
  332. <!-- JS Libraries -->
  333. <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
  334. <script src="/dashboard/javascripts/all.js" type="text/javascript"></script>
  335. </body>
  336. </html>