gocom / danpu Goto Github PK
View Code? Open in Web Editor NEWOptimized MySQL dump library written in PHP
License: MIT License
Optimized MySQL dump library written in PHP
License: MIT License
I am getting this error while trying to import my dump created by danpu:
SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails
SHOW ENGINE INNODB STATUS;
shows me:
Error: Cannot drop table db
.tableX
because it is referenced by db
.tableY
Now, I know I can work around it by setting foreign_key_checks to false.
https://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_foreign_key_checks
But imo it's a dirty solution and I would like to find a proper solution instead. Ideas?
Currently the function executes query by query and fails on one with incorrect syntax. This means that prior queries were executed. So we are left with a half-baked import. Either all or none of the queries should be executed. So maybe it would be a good idea to implement transactions into the import function?
Sorry if this is not how one should suggest this.
protected function import()
{
$query = '';
$this->pdo->beginTransaction();
try {
while (!feof($this->file)) {
$line = fgets($this->file);
$trim = trim($line);
if ($trim === '' || strpos($trim, '--') === 0 || strpos($trim, '/*') === 0) {
continue;
}
if (strpos($trim, 'DELIMITER ') === 0) {
$this->delimiter = substr($trim, 10);
continue;
}
$query .= $line;
if (substr($trim, strlen($this->delimiter) * -1) === $this->delimiter) {
$this->pdo->exec(substr(trim($query), 0, strlen($this->delimiter) * -1));
$query = '';
}
}
$this->pdo->commit();
} catch (\PDOException $e) {
$this->pdo->rollBack();
// throws \PDOException as Exception to make things easier
throw new Exception($e->getMessage(), $e->getCode(), $e);
}
}
is there a way to enable creating the database name ? I looked at config, import, export libraries, I don't see anything there, this would be a really helpful feature.
if I'm importing:
table_1
table_2
and I have a table_3 in my existing database, I expect table_3 to be dropped, currently that's not the case.
This is not the behavior of mysqldump
It would be handy to send an array with included tables instead of only excluding the rest.
I.e.: If you want to include only 2 of the 50 tables you wouldn't have to exclude the other 48.
Missing --single-transaction config option:
https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_single-transaction
Forexample
->createDatabase(true)
->dbName('test_db')
or
->createDatabase('test_db')
exporting and importing a database takes longer than CLI mysqldump. Is there a way to speed this up?
Nothing immediate jumps out in Config.php
specifics: mysqldump created a file of 840M and took approximately 1 minute
this library took just over 15 minutes and created a file size of 930 M
I noticed danpu will place files of 0 bytes (i.e.: Rah_Danpu_CpCOO0
) in the temporary folder if the backup fails for any reason (like unable to connect). Those should be removed to keep the working directory clean.
When running mysqldump from cli I noticed it adds --disable-keys by default.
https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_disable-keys
Would be nice to have that included in danpu.
Temporary file management would be implemented using rah/eien. This would include:
Creating an object does not carry the expectation that something is done behind the scenes. That's not an absolute, though side effects should be kept minimal. Here however, creating the object carries huge side effects, creating a potentially big file or overwriting a database.
Also, you don't necessarily want to do the task at hand right at construction time. Consider dependency injection: component A would get a danpu dumper injected via As constructor. Right now, that isn't possible (or rather it's possible but undesirable, because of the side effect).
Since new Export($foo)
is the only public interface of Export
it is equivalent to a function call, e.g. danpu_export($foo)
. Another way that stays in object oriented confines is moving the side effects to a dedicated public method.
Are you open to moving the side effects? It would require new major version, because it would break compatibility.
For a better compression ratio, turn side it is somewhat slower then gzip.
Is this the correct way to check if the dump/restore went ok?
// Lets try to import the dump or catch the error if any.
try {
new Import($dump);
// Send a successfully restored backup message.
echo "Good job!";
} catch (Exception $e) {
// Oops, something went wrong! Let's show the error..
echo "some error";
}
bringing over database with data hangs
mysql version 5.6.21
Importing exported database on the exact same mysql database via danpu Export,
following exception thrown
Caught exception: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
i cannot read the exported sql file bcoz its read and write protected why
In the case that a php variable is serialized in a field sometimes the import fails.
Currently I don't see why, I try to detect the problem, in the next days.
Will this project support other database adapters such as Postresql and Sql Server?
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.