Skip to content

Commit

Permalink
Change single-transaction so no more SUPER privilege is needed. Closes
Browse files Browse the repository at this point in the history
…ifsnop#54.

Previously, mysqldump-php modified global variables to guarantee transaction.
Now mysqldump-php only sets session variables, so no SUPER privilege is
needed.
start_transaction() has been splitted in two, (setup & start) so it should
be easier to implement a check to query the current transaction level. If
it is not REPEATABLE-READ, set it. Currenlty we are enforcing it.
  • Loading branch information
ifsnop committed Feb 9, 2015
1 parent 1a93aba commit 8e5c9df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ To dump a database, you need the following privileges :
- If any table has one or more triggers.
- **LOCK TABLES**
- If "lock tables" option was enabled.
- **SUPER**
- If "single-transaction" option was enabled.

Use **SHOW GRANTS FOR user@host;** to know what privileges user has. See the following link for more information:

Expand Down
14 changes: 12 additions & 2 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ function prepareListValues($tableName)
);

if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->setup_transaction());
$this->dbHandler->exec($this->typeAdapter->start_transaction());
}

Expand Down Expand Up @@ -969,6 +970,11 @@ public function show_columns()
return "pragma table_info(${args[0]})";
}

public function setup_transaction()
{
return "";
}

public function start_transaction()
{
return "BEGIN EXCLUSIVE";
Expand Down Expand Up @@ -1278,10 +1284,14 @@ public function show_columns()
return "SHOW COLUMNS FROM `${args[0]}`;";
}

public function setup_transaction()
{
return "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";
}

public function start_transaction()
{
return "SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ; " .
"START TRANSACTION";
return "START TRANSACTION";
}

public function commit_transaction()
Expand Down
2 changes: 1 addition & 1 deletion tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'compress' => IMysqldump\Mysqldump::NONE,
'no-data' => false,
'add-drop-table' => true,
'single-transaction' => false,
'single-transaction' => true,
'lock-tables' => true,
'add-locks' => true,
'extended-insert' => false,
Expand Down

0 comments on commit 8e5c9df

Please sign in to comment.