ifsnop / mysqldump-php Goto Github PK
View Code? Open in Web Editor NEWPHP version of mysqldump cli that comes with MySQL
Home Page: https://github.com/ifsnop/mysqldump-php
License: GNU General Public License v3.0
PHP version of mysqldump cli that comes with MySQL
Home Page: https://github.com/ifsnop/mysqldump-php
License: GNU General Public License v3.0
I've found this line in code
@license http://www.gnu.org/copyleft/gpl.html GNU General Public License
But in README license is MIT
Who's right?
See export below. Values that show (by PHPMyAdmin) as NULL are exported as empty string ''
table_name
CREATE TABLE table_name
(
item_id
int(11) NOT NULL auto_increment,
category_id
int(11) default NULL,
title
varchar(255) default NULL,
alias
varchar(255) default NULL,
position
int(11) default NULL,
active
int(11) default NULL,
create_time
datetime default NULL,
modified_time
datetime default NULL,
start_time
date default NULL,
end_time
date default NULL,
key1
varchar(50) default NULL,
key2
varchar(50) default NULL,
key3
varchar(50) default NULL,
PRIMARY KEY (item_id
)
) ENGINE=MyISAM AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;
table_name
INSERT INTO table_name
VALUES('1', '', 'xxx', 'xxx-xxxl', '1', '1', '2013-04-14 21:02:31', '2013-04-14 21:02:31', '', '', '', '', '');
Please export EVENTS
mysql> CREATE EVENT e_totals
-> ON SCHEDULE AT '2006-02-10 23:59:00'
-> DO INSERT INTO test.totals VALUES (NOW());
Hello
I just ran php artisan bundle:install mysqldump-php
as seen from the Laravel website.
However, it comes back with an error:
Fetching [mysqldump-php]...
Warning: file_get_contents(http://nodeload.github.com/clouddueling/mysqldump-php/zipball/master): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in [PATH]/laravel/cli/tasks/bundle/providers/provider.php on line 69
Notice: Undefined variable: bundle in [PATH]/laravel/cli/tasks/bundle/providers/provider.php on line 76
Error downloading bundle [].
all code needs to be converted to PHP-FIG not this rambling of different styles.
Speed up the dump and the insertion of data by adding the following settings before exporting:
Hello
Isn't be better to pass initialized PDO object instead of "'mysql:host=localhost;dbname=testdb', 'username', 'password'" arguments? Many people have PDO already set (CMS etc)
Hi, I want to use MySqlDump in a shared hosted of a client that doesn't allows me to write to files (also doesn't allows me to run exec to mysqldump)..
It is possible that if the filename parameter is empty instead of writing to a file it will return the dump as a string to get it by http ?
Why all the grandfare when all you're doing is exporting a database?
I'm trying to install this on Laravel 3.x but I get "class MySQLDump" not found error.
Any ideas why?
Hi,
Just a small correction.
in getDumpFileHeader there is a
$header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
that is not controled by skip-dump-date
My suggestion:
if (!$this->dumpSettings['skip-dump-date']) {
$header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
}
In order to improve cross-version compatibility, it would be nice to implement code containing comments. This also will make the exports more usable, since executing the backup will result in less errors. Example codes are:
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
This can also be used in order to disable keys on import. It could be an extension of the --add-locks
parameter.
Doesn't order tables or data with respect for foreign keys; the result as-is is cannot be re-imported without modification to the generated sql because of constraints referencing columns in tables yet to be created. There are options that can be added to the script to disable foreign key checks while inserting the data but there is no way around properly ordering the table creation or removing the constraints in the table definitions and adding them after all of the tables have been created.
Hi there,
If you don't mind, and since I have also write access to the repo, I would like to keep updating mysqldump-php (merging PR and adding coding sometimes). I also use mysqldump-php in some of my virtual machines.
Is it ok if you keep ownership and I continue with write access?
OTOH, if you don't want to continue owning this repo, I could take care of it.
Regards,
TypeAdapter code should be refactored to take advantage of some OO techniques.
I can't seem to find a way to set this flag:
--protocol={TCP|SOCKET|PIPE|MEMORY}
The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see Section 4.2.2, “Connecting to the MySQL Server”.
What if I am connecting via a socket?
Or will the library correctly parse the host value?
Mysqldump.php
should consist of only 1 class which has the name of Mysqldump
.CompressMethod
, CompressManagerFactory
, etc should be placed in separated files which have the same name as class.TypeAdapterFactory::show_create_table
should be TypeAdapterFactory::showCreateTable
I just upgraded from Clouddueling/Mysqldump to dev-master using Composer.
I followed the example from the README and it runs great on my PHP 5.5 instances.
I have a few older PHP 5.3.15 instances that show the class not found error. I still have to support those for a short time.
Any thoughts or workarounds?
Fixed in:
5f99e24
please add an option for --complete-insert, that would be tremendously helpful!
thanks
https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_complete-insert
When trying to restore a dump I get the error message:
Error
SQL query: DocumentationEdit Edit
SELECT comment
FROM phpmyadmin
.pma_column_info
WHERE db_name = 'test'
AND table_name = ''
AND column_name = '(db_comment)'
MySQL said: Documentation
#1100 - Table 'pma_column_info' was not locked with LOCK TABLES
I tried both "lock-tables" true and the default (false, according to the documentation)
I think it would be a right way to throw away all these custom var names ($droptableifexists, $nodata and so on) and replace them with commonly used standart names (and add some new features):
add-drop-database
add-drop-table
add-locks
all-databases
complete-insert
delayed-insert
disable-keys
flush-privileges
insert-ignore
lock-all-tables
lock-tables
no-autocommit
no-data
quote-names
replace
Hi, can i get mysqldump output in a variable?
I found a tricky way to do that but is there any simple/quick way to do this?
include_once(dirname(__FILE__) . '/mysqldump-php-1.4.1/src/Ifsnop/Mysqldump/Mysqldump.php');
$dump = new Ifsnop\Mysqldump\Mysqldump( 'database', 'username', 'password');
ob_start();
$dump->start('php://output');
$output = ob_get_contents();
ob_end_clean();
I'm investigating some sort of bug in the behavior of mysqldump, after using it in a VM, mapped on a routed api, after 2 or 3 days of usage, suddenly everything stop working, there is a weird high memory usage on machine and after mysqldump->start it don't write on disk at all,
No error messages. I don't know actually why this is happening, probably it full some buffer,socket or memory somewhere.
This is the "ps aux --sort -rss" result
mysql 32344 0.0 24.0 1152460 460576 pts/2 Sl 10:39 0:02 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
Even restarting mysql it won't help, 2 minutes of using it and it's back on this resources
Hi, earlier I told u about the utf8mb4 character set problem and you solved. This time, when I run the codes using this
$dump = new Mysqldump( $dbname, $dbuser, $dbpass,$dbhost."",'mysql',array('single-transaction' => false,'compress' => 'BZIP2','default-character-set' => Mysqldump::UTF8MB4));
$dump->start('ydk/'.time().'.sql');
And the file saved fine.
But somethings not right.
If I run the codes and db>table>field has '🐈', file saved as ANSI encoding and the cat looked like ğŸ�ˆ
If field has not the '🐈' file saved as UTF8 without BOM
Thank you for solving the problems
Currently, CompressManagerFactory::open() append a file extension to the written dump depending on the enabled compression method (".gz" if GZIP, ".bz2" if BZIP2). I think users should decide the real output filename they want. This will solve many problems to deduct the output filename if internal classes didn't change the filename anymore.
$settings = array(
'compress' => Mysqldump::GZIP
);
$dump = new Mysqldump($db, $username, $password, $host, $type, $settings);
// currently :
$dump->start('dump.sql'); // write dump.sql.gz
// should become :
$dump->start('dump.sql.gz'); // write dump.sql.gz
Hi
i've been experimenting with your library for a bit. I found that while you can write to 'php://sndout' stream you by giving that string as argument it is not possible to provide your own resource.
$handle = fopen('php://temp', 'w+');
$dumper->start($handle);
/* $filesystem is a virtual filesystem, from https://github.com/thephpleague/flysystem */
$filesystem->writeStream($path, $handle);
fclose($handle);
I'v been able to do this for the uncompressed version by modifying the compression class a bit. (basically test if resource then use it and don't close it). However the compressed version need to do gzopen or bzopen so that won't be that easy.
Unfortunately I am not very good at resource handling. I just don't see how to do this - though i think it must be possible with custom stream wrappers. I'm hoping you see a feature like this would be useful and see a way to implement this into a future version...
Thanks!
I constantly got memory exhausted errors at $resultSet = $this->_dbHandler->query($stmt);
Apparently, this was caused by mysqlnd buffering queries: Stack Overflow: Unexpectedly hitting PHP memory limit with a single PDO query?
After adding PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
to $pdoOptions
the script worked.
As this might be a common problem, this solution should be added to the readme, and even perhaps a new parameter could be added to the $settings
array. Alternatively one could work out the impact of making this the default option (performance loss if there's enough memory).
This is the best standalone PHP mysqldump script I have found so far, thanks for all the work! :)
One of the nice features of linux mysqldump is that another database can be the target. In that way it is quite easy to migrate databases.
I think dumping to an external target database also could be a feature of this mysqldump script, since most of the work has already been done for that.
Since most servers support compressed connections, it even should be possible to start to make use of the MYSQL_CLIENT_COMPRESS
client flags.
http://www.php.net/manual/en/mysql.constants.php#mysql.client-flags
This is a suggested feature to improve the script by adding the mysqldump option --hex-blob
Hi Diego
I'm currently writing a small console application which dumps a database and then uploads it to Amazon S3. Consequently this tool is licensed under GPL, as the mysqldump-php project requires. Now what I'm a little unclear about is if I'm allowed to offer a phar binary package. Basically the whole tool inside one binary file. If not, every user would have to compile it himself, which is not really user friendly (but of course I will respect the license).
Thanks for both your great project and feedback!
Cheers,
Marcel
Hey, Thanks guys for your work on this project,
Don't you think it would be nice to be able to export only the data, and skip the table structure ?
option skip-tz-utz
should be skip-tz-utc
Am I the only one with this problem when using mysqldump-php after the last update for using namespaces?
Fatal error: Class 'Clouddueling\Mysqldump\PDO' not found in libs/external/mysqldump-php/src/Clouddueling/Mysqldump/mysqldump.php on line 38
Add port number to the Mysqldump constructor.
Currently it is using the default port number.
I want dump all database schema with all objects (routines, event, procedures, function). Mysqldump-php dump database schema without this object.
Solved
I tried to dump this character properly but it allways return ? ? ?
🎭
🎲
🐈
My friend, can show me hot to solve this problem?
My DB sql
http://tny.cz/a17994ec
Hi
Since the PDO version the dbnames with uppercase characters does not dump any tables anymore.
I think line 220 needs to be modified from
$this->dsnArray[$kvpArr[0]] = strtolower($kvpArr[1]);
to
$this->dsnArray[strtolower($kvpArr[0])] = ($kvpArr[1]);
method getDatabaseStructure():
-consider non empty include-tables.
-foreach removes all the records from $this->dumpSettings'include-tables'
$this->dumpSettings['include-tables'] is now empty resulting dump all the views.
also the set of triigers should respect the set of exported tables - create all the triggers for exported tables and no one for omnited tables
Best regards Adam
When I import the backup, I get an error on the order in which the views were written in the SQL file, there are views that depend on other views, I do not get this error when I run mysqldump.
The white-listing setting "include-tables" does not block all other (not listed) tables.
Create a database containing tables t1, t2 and t3.
Export it with _settings["include-tables"] set to array("t1", "t2").
Tables t1 and t2 exported.
Tables t1, t2 and t3 exported
(Actually, this depends also on the order in which TypeAdapterFactory->showTables() reports the existing tables)
Hi,
I just spent a while trying to figure out an error related to privileges, then I noticed it has been fixed :)
Are you planning a new release soon?
thanks
We need some testing, maybe via
https://travis-ci.org/
We ran the script with more-or-less the same settings as in the README.md example. The output filename was "db_dump.sql.gz".
Running from a browser, this saved as "db_dump.gz.gz".
Unzipping this gave us "db_dump.gz", although that was actually an SQL file.
Somewhere the "sql" was being replaced with "gz" in the content disposition attachment filename.
Worked like a charm otherwise - a life-saver when you don't have command-line access to a server :-)
I try to use mysqldump-php with composer. But i always have this error:
PHP Warning: fopen(/home/www/database/): failed to open stream: Is a directory in /home/www/m10a3/server/vendor/ifsnop/mysqldump-php/src/Ifsnop/Mysqldump/Mysqldump.php on line 824
mysqldump-php error: Output file is not writable
Hello,
I am facing this error on remote server.
SQLSTATE[42000]: Syntax error or access violation: 1227 Access denied; you need (at least one of) the SUPER privilege(s)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.