What is it?
DB-Upload is a new database utility for MySQL. This utility allows you to upload large .SQL files, that phpMyAdmin cannot handle. This will allow you to restore database backups that are several hundred MB big.
Why not use command line/shell/SSH?
You should use the MySQL command line client and shell access to restore a large database. It's the only way that's 100% reliable. But face it, not all web hosts allow you shell access. In fact, most web hosts won't give you access. If you need to restore a big database what do you do? phpMyAdmin can't handle sql files that are bigger than 5 MB, so you're pretty much screwed. But with DB-Upload, you can upload much bigger databases. During testing, I have uploaded databases of 90 MB and 500 MB. It can probably do larger databases as well.
How does it work?
DB-Upload executes the sql file in parts (of 100 KB), instead of doing it all at once. This way, it doesn't have the timeout problems that most PHP scripts have. In addition, it doesn't have any memory issues, because each part is only 100 KB.
The downside of this is time. It will take a while to upload a decent size database. It took me about 15 minutes to upload a 90 MB database on my localhost. It probably takes longer on a live server.
Instructions
- Download the utility: db-upload.php
1
2
3/*
4DB-Upload Utility - By Dennis Pallett ([email protected])
5http://www.nocertainty.com
6
7Made available under the GNU General Public License (GPL)
8http://www.gnu.org/licenses/gpl.txt
9*/
10
11ob_start ();
12error_reporting ( E_ALL ^ E_NOTICE );
13
14// Define file sizes
15DEFINE ( "KB" , 1024 );
16DEFINE ( "MB" , 1024 * 1024 );
17DEFINE ( "GB" , 1024 * 1024 * 1024 );
18
19$_GET = strip_gpc_slashes ( $_GET );
20
21// Get settings
22$filename = $_GET [ 'filename' ];
23$db_host = $_GET [ 'db_host' ];
24$db_name = $_GET [ 'db_name' ];
25$db_user = $_GET [ 'db_user' ];
26$db_password = $_GET [ 'db_password' ];
27
28// Are there any settings?
29if (empty( $filename ) OR empty( $db_host ) OR empty( $db_name ) OR empty( $db_password )) {
30// Show the settings form:
1<html>
2<head>
3<title>DB-Upload Utility</title>
4</head>
5<style type="text/css">
6body {
7background-color: #EFEFEF;
8font-family: Verdana, Arial, Times New Roman;
9}
10
11h2 {
12font-size: 120%;
13font-weight: normal;
14margin-left: 15px;
15}
16
17th {
18font-size: 0.7em;
19text-align: right;
20padding-right: 10px;
21vertical-align: top;
22}
23
24td {
25font-size: 62.5%; /* Resets 1em to 10px */
26}
27
28div {
29background-color: #FFF;
30border: 1px solid black;
31padding: 15px;
32padding-bottom: 0px;
33text-align: center;
34}
35
36#submit {
37font-family: Verdana;
38font-weight: bold;
39font-size: 0.7em;
40padding: 2px 60px;
41margin-top: 15px;
42}
43</style>
44<body>
45<div>
46<h2>DB-Upload Utility</h2>
47<form method="GET">
48<table border="0">
49<tr>
50<th scope="col">Filepath:</th>
51<td><input name="filename" size="100" type="text"/><br/>Path to the SQL on your server, e.g. /home/dennis/public_html/mydb.sql
52</td>
53</tr>
54<tr>
55<th scope="col">DB Host:</th>
56<td><input name="db_host" type="text" value="localhost"/></td>
57</tr>
58<tr>
59<th scope="col">DB Name:</th>
60<td><input name="db_name" type="text"/></td>
61</tr>
62<tr>
63<th scope="col">DB User:</th>
64<td><input name="db_user" type="text"/></td>
65</tr>
66<tr>
67<th scope="col">DB Password:</th>
68<td><input name="db_password" type="password"/></td>
69</tr>
70</table>
71<input id="submit" type="submit" value="Upload Database"/>
72</form>
73</div>
74</body>
75</html>
DB-Upload Utility: Status
Size Read: | ``` echo $newbegin ; ``` out of ``` echo ( $filesize ); ``` bytes ( ``` echo round ( $newbegin / MB , 2 ); ``` out of ``` echo round ( $filesize / MB , 2 ); ``` MB) |
---|---|
Size Executed: | ``` echo $newbegin ; ``` out of ``` echo ( $filesize ); ``` bytes ( ``` echo round ( $newbegin / MB , 2 ); ``` out of ``` echo round ( $filesize / MB , 2 ); ``` MB) |
Percentage Completed: | ``` echo round (( $newbegin / $filesize )* 100 , 2 ); ``` % |
Your SQL file has been uploaded, and all the queries have been successfully executed.