diff --git a/.env.mysql b/.env.mysql new file mode 100644 index 00000000..fb32c0cd --- /dev/null +++ b/.env.mysql @@ -0,0 +1,5 @@ +MARIADB_ROOT_PASSWORD=mysql +MYSQL_ROOT_PASSWORD=mysql +MYSQL_DATABASE=mysql +MYSQL_USER=mysql +MYSQL_PASSWORD=mysql diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c832731b..c4db4159 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,7 @@ on: branches: # Push events on main branch - main + - php-8.4 pull_request: jobs: @@ -13,84 +14,69 @@ jobs: runs-on: ${{ matrix.os }} + services: + db: + image: ${{ matrix.database_image }} + env: + # The MySQL docker container requires these environment variables to be set + # so we can create and migrate the test database. + # See: https://hub.docker.com/_/mysql + MARIADB_ROOT_PASSWORD: example + MYSQL_ROOT_PASSWORD: example + MYSQL_DATABASE: example + MYSQL_USER: example + MYSQL_PASSWORD: example + MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password + ports: + # Opens port 3306 on service container and host + # https://docs.github.com/en/actions/using-containerized-services/about-service-containers + - 3306:3306 + # Before continuing, verify the mysql container is reachable from the ubuntu host + options: --name db --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + strategy: fail-fast: false matrix: include: - # MySQL 5.7 - - os: ubuntu-20.04 - database: 'mysql' - database-version: '5.7' - php-version: '7.4' - - os: ubuntu-20.04 - database: 'mysql' - database-version: '5.7' - php-version: '8.0' - - os: ubuntu-20.04 - database: 'mysql' - database-version: '5.7' - php-version: '8.1' - - os: ubuntu-20.04 - database: 'mysql' - database-version: '5.7' - php-version: '8.2' - - os: ubuntu-20.04 - database: 'mysql' - database-version: '5.7' - php-version: '8.3' + # MySQL 8.0 - os: ubuntu-latest - database: 'mysql' - database-version: '8.0' - php-version: '7.4' - - os: ubuntu-latest - database: 'mysql' - database-version: '8.0' - php-version: '8.0' + database: mysql + database_image: bitnami/mysql:8.0 + php-version: 8.1 - os: ubuntu-latest - database: 'mysql' - database-version: '8.0' - php-version: '8.1' + database: mysql + database_image: bitnami/mysql:8.0 + php-version: 8.2 - os: ubuntu-latest - database: 'mysql' - database-version: '8.0' - php-version: '8.2' + database: mysql + database_image: bitnami/mysql:8.0 + php-version: 8.3 - os: ubuntu-latest - database: 'mysql' - database-version: '8.0' - php-version: '8.3' + database: mysql + database_image: bitnami/mysql:8.0 + php-version: 8.4 + # MariaDB 10.11 LTS - os: ubuntu-20.04 - database: 'mariadb' - database-version: '10.11' - php-version: '7.4' + database: mariadb + database_image: bitnami/mariadb:10.11 + php-version: 8.1 - os: ubuntu-20.04 - database: 'mariadb' - database-version: '10.11' - php-version: '8.0' + database: mariadb + database_image: bitnami/mariadb:10.11 + php-version: 8.2 - os: ubuntu-20.04 - database: 'mariadb' - database-version: '10.11' - php-version: '8.1' + database: mariadb + database_image: bitnami/mariadb:10.11 + php-version: 8.3 - os: ubuntu-20.04 - database: 'mariadb' - database-version: '10.11' - php-version: '8.2' - - os: ubuntu-20.04 - database: 'mariadb' - database-version: '10.11' - php-version: '8.3' + database: mariadb + database_image: bitnami/mariadb:10.11 + php-version: 8.4 steps: - - uses: shogo82148/actions-setup-mysql@v1 - with: - distribution: '${{ matrix.database }}' - mysql-version: '${{ matrix.database-version }}' - user: 'travis' - password: '' - root-password: 'drupal' - - name: Checkout code uses: actions/checkout@v4 with: @@ -112,7 +98,11 @@ jobs: run: vendor/bin/phpunit - name: Create user and databases for testing - run: cd tests/scripts && ./create_users.sh 127.0.0.1 + run: cat docker-entrypoint-initdb.d/${{ matrix.database }}-init.sql | mysql -h127.0.0.1 -uroot -pexample - name: Run test script - run: cd tests/scripts && ./test.sh 127.0.0.1 + run: | + shopt -s expand_aliases + alias mysqldump='docker exec db mysqldump' + mysqldump --version + cd tests/scripts && ./test.sh 127.0.0.1 diff --git a/Dockerfile b/Dockerfile index 9ff91d93..b088fcf9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,14 @@ -ARG PHP_SHORT_VERSION +ARG PHP_SHORT_VERSION=81 -FROM druidfi/php:7.4 AS php-74 - -RUN sudo apk --update -X https://dl-cdn.alpinelinux.org/alpine/edge/testing --no-cache add php7-pdo php7-pdo_mysql - -FROM druidfi/php:8.0 AS php-80 - -RUN sudo apk --update --no-cache add php8-pdo php8-pdo_mysql - -FROM druidfi/php:8.1 AS php-81 - -RUN sudo apk --update --no-cache add php81-pdo php81-pdo_mysql - -FROM druidfi/php:8.2 AS php-82 - -RUN sudo apk --update -X https://dl-cdn.alpinelinux.org/alpine/edge/community --no-cache add php82-pdo php82-pdo_mysql - -FROM druidfi/php:8.3 AS php-83 - -RUN sudo apk --update -X https://dl-cdn.alpinelinux.org/alpine/edge/community --no-cache add php83-pdo php83-pdo_mysql +FROM php:8.1-alpine AS php-81 +FROM php:8.2-alpine AS php-82 +FROM php:8.3-alpine AS php-83 +FROM php:8.4-alpine AS php-84 FROM php-${PHP_SHORT_VERSION} -RUN sudo apk --update --no-cache add bash mysql-client \ - && sudo rm -rf /var/cache/apk/* +RUN docker-php-ext-install pdo pdo_mysql +RUN apk --update --no-cache add bash mysql-client WORKDIR /app diff --git a/README.md b/README.md index e6e8b51b..38af158f 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,14 @@ Out of the box, `mysqldump-php` supports backing up table structures, the data i ## Requirements -- PHP 7.4 or 8.x with PDO - [see supported versions](https://www.php.net/supported-versions.php) -- MySQL 5.7 or newer (and compatible MariaDB) +- PHP 8.1 or newer with PDO - [see supported versions](https://www.php.net/supported-versions.php) +- MySQL 8.0 or newer (and compatible MariaDB) ## Installing Install using [Composer](https://getcomposer.org/): -``` +```console composer require druidfi/mysqldump-php ``` @@ -239,29 +239,19 @@ Local setup for tests: ```console docker compose up --wait --build -docker compose exec php81 /app/tests/scripts/create_users.sh -docker compose exec php81 /app/tests/scripts/create_users.sh db2 -docker compose exec php81 /app/tests/scripts/create_users.sh db3 -docker compose exec -w /app/tests/scripts php74 ./test.sh -docker compose exec -w /app/tests/scripts php80 ./test.sh -docker compose exec -w /app/tests/scripts php81 ./test.sh -docker compose exec -w /app/tests/scripts php82 ./test.sh -docker compose exec -w /app/tests/scripts php83 ./test.sh -docker compose exec -w /app/tests/scripts php74 ./test.sh db2 -docker compose exec -w /app/tests/scripts php80 ./test.sh db2 -docker compose exec -w /app/tests/scripts php81 ./test.sh db2 -docker compose exec -w /app/tests/scripts php82 ./test.sh db2 -docker compose exec -w /app/tests/scripts php83 ./test.sh db2 -docker compose exec -w /app/tests/scripts php74 ./test.sh db3 -docker compose exec -w /app/tests/scripts php80 ./test.sh db3 -docker compose exec -w /app/tests/scripts php81 ./test.sh db3 -docker compose exec -w /app/tests/scripts php82 ./test.sh db3 -docker compose exec -w /app/tests/scripts php83 ./test.sh db3 +docker compose exec -w /app/tests/scripts php81 ./test.sh mysql +docker compose exec -w /app/tests/scripts php82 ./test.sh mysql +docker compose exec -w /app/tests/scripts php83 ./test.sh mysql +docker compose exec -w /app/tests/scripts php84 ./test.sh mysql +docker compose exec -w /app/tests/scripts php81 ./test.sh mariadb +docker compose exec -w /app/tests/scripts php82 ./test.sh mariadb +docker compose exec -w /app/tests/scripts php83 ./test.sh mariadb +docker compose exec -w /app/tests/scripts php84 ./test.sh mariadb ``` ## Credits -Forked from Diego Torres's version which have latest updates from 2020. Use it for PHP 7.3 and older. +Forked from Diego Torres's version which have latest updates from 2020. Use it for PHP 8.0 and older. https://github.com/ifsnop/mysqldump-php Originally based on James Elliott's script from 2009. diff --git a/compose.yaml b/compose.yaml index 2a9b3452..3d0b50b8 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,91 +1,65 @@ -version: '3.7' - services: - db: - container_name: mysqldump-php-mysql-57 - image: druidfi/mysql:5.7-drupal - ports: - - 3306 - - db2: + mysql: container_name: mysqldump-php-mysql-80 - image: druidfi/mysql:8.0-drupal - ports: - - 3306 - - db3: - container_name: mysqldump-php-mariadb-80 - image: druidfi/mariadb:10.11-drupal - ports: - - 3306 - - php74: - container_name: mysqldump-php-74 - image: mysqldump-php-tester:php-7.4 - build: - context: . - args: - PHP_SHORT_VERSION: "74" + image: bitnami/mysql:8.0 + env_file: + - .env.mysql volumes: - - .:/app - depends_on: - - db - - db2 - - db3 + - ./docker-entrypoint-initdb.d/mysql-init.sql:/docker-entrypoint-initdb.d/00-init.sql - php80: - container_name: mysqldump-php-80 - image: mysqldump-php-tester:php-8.0 - build: - context: . - args: - PHP_SHORT_VERSION: "80" + mariadb: + container_name: mysqldump-php-mariadb-10 + image: bitnami/mariadb:10.11 + env_file: + - .env.mysql volumes: - - .:/app - depends_on: - - db - - db2 - - db3 + - ./docker-entrypoint-initdb.d/mariadb-init.sql:/docker-entrypoint-initdb.d/00-init.sql php81: container_name: mysqldump-php-81 - image: mysqldump-php-tester:php-8.1 build: context: . args: - PHP_SHORT_VERSION: "81" + PHP_SHORT_VERSION: 81 volumes: - .:/app depends_on: - - db - - db2 - - db3 + - mysql + - mariadb php82: container_name: mysqldump-php-82 - image: mysqldump-php-tester:php-8.2 build: context: . args: - PHP_SHORT_VERSION: "82" + PHP_SHORT_VERSION: 82 volumes: - .:/app depends_on: - - db - - db2 - - db3 + - mysql + - mariadb php83: container_name: mysqldump-php-83 - image: mysqldump-php-tester:php-8.3 build: context: . args: - PHP_SHORT_VERSION: "83" + PHP_SHORT_VERSION: 83 + volumes: + - .:/app + depends_on: + - mysql + - mariadb + + php84: + container_name: mysqldump-php-84 + build: + context: . + args: + PHP_SHORT_VERSION: 84 volumes: - .:/app depends_on: - - db - - db2 - - db3 + - mysql + - mariadb diff --git a/composer.json b/composer.json index dcbb9a28..100f3e26 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "druidfi/mysqldump-php", "description": "PHP version of mysqldump cli that comes with MySQL", "type": "library", - "keywords": ["mysql", "mysqldump", "pdo", "php7", "php8", "database", "php", "sql", "mariadb", "mysql-backup"], + "keywords": ["mysql", "mysqldump", "pdo", "php8", "database", "php", "sql", "mariadb", "mysql-backup"], "homepage": "https://github.com/druidfi/mysqldump-php", "license": "GPL-3.0-or-later", "minimum-stability": "stable", @@ -18,13 +18,13 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "composer-runtime-api": "^2", "ext-pdo": "*" }, "require-dev": { "squizlabs/php_codesniffer": "3.*", - "phpunit/phpunit": "^8.5.15 || ^9" + "phpunit/phpunit": "^9" }, "autoload": { "psr-4": { diff --git a/docker-entrypoint-initdb.d/mariadb-init.sql b/docker-entrypoint-initdb.d/mariadb-init.sql new file mode 100644 index 00000000..edfb5f3d --- /dev/null +++ b/docker-entrypoint-initdb.d/mariadb-init.sql @@ -0,0 +1,30 @@ +CREATE USER IF NOT EXISTS 'example'@'%' IDENTIFIED BY 'example'; +GRANT ALL ON *.* TO 'example'@'%'; + +CREATE DATABASE IF NOT EXISTS test001; +CREATE DATABASE IF NOT EXISTS test002; +CREATE DATABASE IF NOT EXISTS test005; +CREATE DATABASE IF NOT EXISTS test006a; +CREATE DATABASE IF NOT EXISTS test006b; +CREATE DATABASE IF NOT EXISTS test008; +CREATE DATABASE IF NOT EXISTS test009; +CREATE DATABASE IF NOT EXISTS test010; +CREATE DATABASE IF NOT EXISTS test011; +CREATE DATABASE IF NOT EXISTS test012; +CREATE DATABASE IF NOT EXISTS test014; +GRANT ALL PRIVILEGES ON test001.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test002.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test005.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test006a.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test006b.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test008.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test009.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test010.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test011.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test012.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test014.* TO 'example'@'%' WITH GRANT OPTION; +GRANT PROCESS,SUPER,LOCK TABLES ON *.* TO 'example'@'%'; + +FLUSH PRIVILEGES; + +SHOW databases; diff --git a/docker-entrypoint-initdb.d/mysql-init.sql b/docker-entrypoint-initdb.d/mysql-init.sql new file mode 100644 index 00000000..7c77a2d9 --- /dev/null +++ b/docker-entrypoint-initdb.d/mysql-init.sql @@ -0,0 +1,30 @@ +CREATE USER IF NOT EXISTS 'example'@'%' IDENTIFIED WITH mysql_native_password BY 'example'; +GRANT ALL ON *.* TO 'example'@'%'; + +CREATE DATABASE IF NOT EXISTS test001; +CREATE DATABASE IF NOT EXISTS test002; +CREATE DATABASE IF NOT EXISTS test005; +CREATE DATABASE IF NOT EXISTS test006a; +CREATE DATABASE IF NOT EXISTS test006b; +CREATE DATABASE IF NOT EXISTS test008; +CREATE DATABASE IF NOT EXISTS test009; +CREATE DATABASE IF NOT EXISTS test010; +CREATE DATABASE IF NOT EXISTS test011; +CREATE DATABASE IF NOT EXISTS test012; +CREATE DATABASE IF NOT EXISTS test014; +GRANT ALL PRIVILEGES ON test001.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test002.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test005.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test006a.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test006b.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test008.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test009.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test010.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test011.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test012.* TO 'example'@'%' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON test014.* TO 'example'@'%' WITH GRANT OPTION; +GRANT PROCESS,SUPER,LOCK TABLES ON *.* TO 'example'@'%'; + +FLUSH PRIVILEGES; + +SHOW databases; diff --git a/tests/scripts/create_users.sh b/tests/scripts/create_users.sh deleted file mode 100755 index 00abd601..00000000 --- a/tests/scripts/create_users.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -HOST=${1:-db} -MYSQL_ROOT_PASSWORD=drupal -MYSQL_CMD="mysql -h $HOST -u root -p$MYSQL_ROOT_PASSWORD" -USER=travis - -major=`$MYSQL_CMD -e "SELECT @@version\G" | grep version |awk '{print $2}' | awk -F"." '{print $1}'` -medium=`$MYSQL_CMD -e "SELECT @@version\G" | grep version |awk '{print $2}' | awk -F"." '{print $2}'` -minor=`$MYSQL_CMD -e "SELECT @@version\G" | grep version |awk '{print $2}' | awk -F"." '{print $3}'` - -printf "\nCreating users in MySQL server version $major.$medium.$minor on host '$HOST' with user '$USER'\n\n" - -$MYSQL_CMD -e "CREATE USER IF NOT EXISTS '$USER'@'%';" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test001;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test002;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test005;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test006a;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test006b;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test008;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test009;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test010;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test011;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test012;" -$MYSQL_CMD -e "CREATE DATABASE IF NOT EXISTS test014;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test001.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test002.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test005.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test006a.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test006b.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test008.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test009.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test010.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test011.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test012.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT ALL PRIVILEGES ON test014.* TO '$USER'@'%' WITH GRANT OPTION;" -$MYSQL_CMD -e "GRANT PROCESS,SUPER,LOCK TABLES ON *.* TO '$USER'@'%';" - -if [[ $major -eq 5 && $medium -ge 7 ]]; then - $MYSQL_CMD -e "GRANT SELECT ON mysql.proc to '$USER'@'%';" -fi - -if [[ $major -eq 5 && $medium -ge 7 ]]; then - $MYSQL_CMD -e "use mysql; update user set authentication_string=PASSWORD('') where User='$USER'; update user set plugin='mysql_native_password';" -fi - -$MYSQL_CMD -e "FLUSH PRIVILEGES;" - -echo "Listing created databases with user '$USER'" -mysql -h $HOST -u $USER -e "SHOW databases;" diff --git a/tests/scripts/pdo_checks.php b/tests/scripts/pdo_checks.php index c9d11099..f6ed77be 100644 --- a/tests/scripts/pdo_checks.php +++ b/tests/scripts/pdo_checks.php @@ -4,14 +4,15 @@ error_reporting(E_ALL); $host = $argv[1] ?? 'db'; // Get host name from test.sh -$user = 'travis'; +$user = 'example'; +$pass = 'example'; $expected_double = '-2.2250738585072014e-308'; $ret = 0; print "PHP version is ". phpversion() . PHP_EOL; print "PDO check: double field" . PHP_EOL . PHP_EOL; -$db = new \PDO("mysql:host=$host;dbname=test001", $user, null, [ +$db = new \PDO("mysql:host=$host;dbname=test001", $user, $pass, [ \PDO::ATTR_PERSISTENT => true, \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false, diff --git a/tests/scripts/test.php b/tests/scripts/test.php index 941c6247..39a15bc2 100644 --- a/tests/scripts/test.php +++ b/tests/scripts/test.php @@ -9,11 +9,12 @@ use Druidfi\Mysqldump\Mysqldump; use Druidfi\Mysqldump\Compress\CompressManagerFactory; -$host = $argv[1] ?? 'db'; // Get host name from test.sh -$user = 'travis'; +$host = $argv[1] ?? 'mysql'; // Get host name from test.sh +$user = 'example'; +$pass = 'example'; $dumpSettings = [ - 'exclude-tables' => ['/^travis*/'], + 'exclude-tables' => ['/^example*/'], 'compress' => CompressManagerFactory::NONE, 'no-data' => false, 'add-drop-table' => true, @@ -29,153 +30,191 @@ 'add-drop-database' => false, 'hex-blob' => true, 'no-create-info' => false, - 'where' => '' + 'where' => '', ]; try { // do nothing test print "Create dump with PHP: mysql-php_test000.sql" . PHP_EOL; - $dump = new Mysqldump("mysql:host=$host;dbname=test001", $user); + $dump = new Mysqldump("mysql:host=$host;dbname=test001", $user, $pass); print "Create dump with PHP: mysql-php_test001.sql" . PHP_EOL; - $dump = new Mysqldump("mysql:host=$host;dbname=test001", $user, "", $dumpSettings); + $dump = new Mysqldump("mysql:host=$host;dbname=test001", $user, $pass, $dumpSettings); $dump->start("output/mysqldump-php_test001.sql"); // checks if complete-insert && hex-blob works ok together print "Create dump with PHP: mysql-php_test001_complete.sql" . PHP_EOL; $dumpSettings['complete-insert'] = true; - $dump = new Mysqldump("mysql:host=$host;dbname=test001", $user, "", $dumpSettings); + $dump = new Mysqldump("mysql:host=$host;dbname=test001", $user, $pass, $dumpSettings); $dump->start("output/mysqldump-php_test001_complete.sql"); print "Create dump with PHP: mysql-php_test002.sql" . PHP_EOL; $dumpSettings['default-character-set'] = DumpSettings::UTF8MB4; $dumpSettings['complete-insert'] = true; - $dump = new Mysqldump("mysql:host=$host;dbname=test002", $user, "", $dumpSettings); + $dump = new Mysqldump("mysql:host=$host;dbname=test002", $user, $pass, $dumpSettings); $dump->start("output/mysqldump-php_test002.sql"); print "Create dump with PHP: mysql-php_test005.sql" . PHP_EOL; $dumpSettings['complete-insert'] = false; - $dump = new Mysqldump("mysql:host=$host;dbname=test005", $user, "", $dumpSettings); + $dump = new Mysqldump("mysql:host=$host;dbname=test005", $user, $pass, $dumpSettings); $dump->start("output/mysqldump-php_test005.sql"); print "Create dump with PHP: mysql-php_test006.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test006a", $user, - "", - ["no-data" => true, "add-drop-table" => true] + $pass, + [ + "no-data" => true, + "add-drop-table" => true, + ] ); + $dump->start("output/mysqldump-php_test006.sql"); print "Create dump with PHP: mysql-php_test008.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test008", $user, - "", - ["no-data" => true, "add-drop-table" => true] + $pass, + [ + "no-data" => true, + "add-drop-table" => true, + ] ); + $dump->start("output/mysqldump-php_test008.sql"); print "Create dump with PHP: mysql-php_test009.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test009", $user, - "", - ["no-data" => true, "add-drop-table" => true, "reset-auto-increment" => true, "add-drop-database" => true] + $pass, + [ + "no-data" => true, + "add-drop-table" => true, + "reset-auto-increment" => true, + "add-drop-database" => true, + ] ); + $dump->start("output/mysqldump-php_test009.sql"); print "Create dump with PHP: mysql-php_test010.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test010", $user, - "", - ["events" => true] + $pass, + [ + "events" => true, + ] ); + $dump->start("output/mysqldump-php_test010.sql"); print "Create dump with PHP: mysql-php_test011a.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test011", $user, - "", - ['complete-insert' => false] + $pass, + [ + 'complete-insert' => false, + ] ); + $dump->start("output/mysqldump-php_test011a.sql"); print "Create dump with PHP: mysql-php_test011b.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test011", $user, - "", + $pass, [ - 'complete-insert' => true, + 'complete-insert' => true, ] ); + $dump->start("output/mysqldump-php_test011b.sql"); print "Create dump with PHP: mysql-php_test012.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test012", $user, - "", + $pass, [ - 'events' => true, - 'skip-triggers' => false, - 'routines' => true, - 'add-drop-trigger' => true, + 'events' => true, + 'skip-triggers' => false, + 'routines' => true, + 'add-drop-trigger' => true, ] ); + $dump->start("output/mysqldump-php_test012.sql"); print "Create dump with PHP: mysql-php_test012b_no-definer.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test012", $user, - "", + $pass, [ - "events" => true, - 'skip-triggers' => false, - 'routines' => true, - 'add-drop-trigger' => true, - 'skip-definer' => true, + "events" => true, + 'skip-triggers' => false, + 'routines' => true, + 'add-drop-trigger' => true, + 'skip-definer' => true, ] ); + $dump->start("output/mysqldump-php_test012_no-definer.sql"); print "Create dump with PHP: mysql-php_test013.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test001", $user, - "", + $pass, [ - "insert-ignore" => true, - "extended-insert" => false + "insert-ignore" => true, + "extended-insert" => false, ] ); + $dump->start("output/mysqldump-php_test013.sql"); print "Create dump with PHP: mysql-php_test014a.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test014", $user, - "", + $pass, [ 'complete-insert' => false, 'hex-blob' => true, - ] ); + ] + ); + $dump->start("output/mysqldump-php_test014a.sql"); print "Create dump with PHP: mysql-php_test014b.sql" . PHP_EOL; + $dump = new Mysqldump( "mysql:host=$host;dbname=test014", $user, - "", + $pass, [ 'complete-insert' => true, 'hex-blob' => true, ] ); + $dump->start("output/mysqldump-php_test014b.sql"); exit(0); diff --git a/tests/scripts/test.sh b/tests/scripts/test.sh index aef10243..fde194c6 100755 --- a/tests/scripts/test.sh +++ b/tests/scripts/test.sh @@ -1,9 +1,10 @@ #!/bin/bash -HOST=${1:-db} -USER=travis -MYSQL_CMD="mysql -h $HOST -u $USER" -MYSQLDUMP_CMD="mysqldump -h $HOST -u $USER" +HOST=${1:-mysql} +USER=example +PASS=example +MYSQL_CMD="mysql -h $HOST -u $USER -p$PASS" +MYSQLDUMP_CMD="mysqldump -h $HOST -u $USER -p$PASS" major=`$MYSQL_CMD -e "SELECT @@version\G" | grep version |awk '{print $2}' | awk -F"." '{print $1}'` medium=`$MYSQL_CMD -e "SELECT @@version\G" | grep version |awk '{print $2}' | awk -F"." '{print $2}'` @@ -71,18 +72,9 @@ else if [[ $errCode -ne 0 ]]; then echo "error test010.8.src.sql"; fi fi -if [[ $major -eq 5 && $medium -ge 7 ]]; then - printf "Import test011.src.sql" - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - $MYSQL_CMD < test011.src.sql && echo " - done."; errCode=$?; ret[((index++))]=$errCode -else - echo "test011 disabled, only valid for mysql server version 5.7.x" -fi - printf "Import test012.src.sql" $MYSQL_CMD < test012.src.sql && echo " - done."; errCode=$?; ret[((index++))]=$errCode if [[ $errCode -ne 0 ]]; then echo "error test012.src.sql"; fi -#$MYSQL_CMD < test013.src.sql; errCode=$?; ret[((index++))]=$errCode printf "Import test014.src.sql" $MYSQL_CMD < test014.src.sql && echo " - done."; errCode=$?; ret[((index++))]=$errCode @@ -198,21 +190,6 @@ cat test002.src.sql | grep ^INSERT > output/test002.filtered.sql && echo "Create cat test005.src.sql | grep ^INSERT > output/test005.filtered.sql && echo "Created test005.filtered.sql" cat test008.src.sql | grep FOREIGN > output/test008.filtered.sql && echo "Created test008.filtered.sql" cat test010.src.sql | grep CREATE | grep EVENT > output/test010.filtered.sql && echo "Created test010.filtered.sql" - -if [[ $major -eq 5 && $medium -ge 7 ]]; then - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - cat test011.src.sql | egrep "INSERT|GENERATED" > output/test011.filtered.sql && echo "Created test011.filtered.sql" -else - echo "test011 disabled, only valid for mysql server version 5.7.x" -fi - -if [[ $major -eq 5 && $medium -ge 7 ]]; then - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - cat test014.src.sql | egrep "INSERT|GENERATED" > output/test014.filtered.sql && echo "Created test014.filtered.sql" -else - echo "test014 disabled, only valid for mysql server version 5.7.x" -fi - cat output/mysqldump_test001.sql | grep ^INSERT > output/mysqldump_test001.filtered.sql && echo "Created mysqldump_test001.filtered.sql" cat output/mysqldump_test001_complete.sql | grep ^INSERT > output/mysqldump_test001_complete.filtered.sql && echo "Created mysqldump_test001_complete.filtered.sql" cat output/mysqldump_test002.sql | grep ^INSERT > output/mysqldump_test002.filtered.sql && echo "Created mysqldump_test002.filtered.sql" @@ -226,25 +203,9 @@ cat output/mysqldump-php_test005.sql | grep ^INSERT > output/mysqldump-php_test0 cat output/mysqldump-php_test008.sql | grep FOREIGN > output/mysqldump-php_test008.filtered.sql && echo "Created mysqldump-php_test008.filtered.sql" cat output/mysqldump-php_test010.sql | grep CREATE | grep EVENT > output/mysqldump-php_test010.filtered.sql && echo "Created mysqldump-php_test010.filtered.sql" -if [[ $major -eq 5 && $medium -ge 7 ]]; then - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - cat output/mysqldump-php_test011a.sql | egrep "INSERT|GENERATED" > output/mysqldump-php_test011a.filtered.sql && echo "Created mysqldump-php_test011a.filtered.sql" - cat output/mysqldump-php_test011b.sql | egrep "INSERT|GENERATED" > output/mysqldump-php_test011b.filtered.sql && echo "Created mysqldump-php_test011b.filtered.sql" -else - echo "test011 disabled, only valid for mysql server version 5.7.x" -fi - cat output/mysqldump-php_test012.sql | grep -E -e '50001 (CREATE|VIEW)' -e '50013 DEFINER' -e 'CREATE.*TRIGGER' -e 'FUNCTION' -e 'PROCEDURE' > output/mysqldump-php_test012.filtered.sql && echo "Created mysqldump-php_test012.filtered.sql" cat output/mysqldump-php_test013.sql | grep INSERT > output/mysqldump-php_test013.filtered.sql && echo "Created mysqldump-php_test013.filtered.sql" -if [[ $major -eq 5 && $medium -ge 7 ]]; then - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - cat output/mysqldump-php_test014a.sql | egrep "INSERT|GENERATED" > output/mysqldump-php_test014a.filtered.sql && echo "Created mysqldump-php_test014a.filtered.sql" - cat output/mysqldump-php_test014b.sql | egrep "INSERT|GENERATED" > output/mysqldump-php_test014b.filtered.sql && echo "Created mysqldump-php_test014b.filtered.sql" -else - echo "test014 disabled, only valid for mysql server version 5.7.x" -fi - printf "\nRun diff tests:\n\n" test="Test#$index diff test001.filtered.sql mysqldump_test001.filtered.sql" @@ -312,20 +273,6 @@ diff output/test010.filtered.sql output/mysqldump-php_test010.filtered.sql errCode=$?; ret[((index++))]=$errCode if [[ $errCode -ne 0 ]]; then echo -e "\n$test\n"; fi -if [[ $major -eq 5 && $medium -ge 7 ]]; then - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - test="Test#$index diff test011.filtered.sql mysqldump-php_test011a.filtered.sql" - diff output/test011.filtered.sql output/mysqldump-php_test011a.filtered.sql - errCode=$?; ret[((index++))]=$errCode - if [[ $errCode -ne 0 ]]; then echo -e "\n$test\n"; fi - test="Test#$index diff test011.filtered.sql mysqldump-php_test011b.filtered.sql" - diff output/test011.filtered.sql output/mysqldump-php_test011b.filtered.sql - errCode=$?; ret[((index++))]=$errCode - if [[ $errCode -ne 0 ]]; then echo -e "\n$test\n"; fi -else - echo "test011 disabled, only valid for mysql server version 5.7.x" -fi - # Test create views, events, trigger test="Test#$index diff mysqldump_test012.filtered.sql mysqldump-php_test012.filtered.sql" diff output/mysqldump_test012.filtered.sql output/mysqldump-php_test012.filtered.sql @@ -344,19 +291,6 @@ diff output/mysqldump_test013.filtered.sql output/mysqldump-php_test013.filtered errCode=$?; ret[((index++))]=$errCode if [[ $errCode -ne 0 ]]; then echo -e "\n$test\n"; fi -if [[ $major -eq 5 && $medium -ge 7 ]]; then - # test virtual column support, with simple inserts forced to complete (a) and complete inserts (b) - test="Test#$index diff test014.filtered.sql mysqldump-php_test014a.filtered.sql" - diff output/test014.filtered.sql output/mysqldump-php_test014a.filtered.sql - errCode=$?; ret[((index++))]=$errCode - if [[ $errCode -ne 0 ]]; then echo -e "\n$test\n"; fi - test="Test#$index diff test014.filtered.sql mysqldump-php_test014b.filtered.sql" - diff output/test014.filtered.sql output/mysqldump-php_test014b.filtered.sql - errCode=$?; ret[((index++))]=$errCode - if [[ $errCode -ne 0 ]]; then echo -e "\n$test\n"; fi -else - echo "test011 disabled, only valid for mysql server version 5.7.x" -fi echo -e "\nDone $index tests\n" retvalue=0 diff --git a/tests/scripts/test001.src.sql b/tests/scripts/test001.src.sql index 43622e0b..4515a745 100644 --- a/tests/scripts/test001.src.sql +++ b/tests/scripts/test001.src.sql @@ -113,10 +113,10 @@ INSERT INTO `test033` VALUES (1,'test test test'); DROP VIEW IF EXISTS `test100`; -CREATE ALGORITHM=UNDEFINED DEFINER=`travis`@`localhost` SQL SECURITY DEFINER VIEW `test100` AS select `test000`.`id` AS `id`,`test000`.`col01` AS `col01`,`test000`.`col02` AS `col02`,`test000`.`col03` AS `col03`,`test000`.`col10` AS `col10`,`test000`.`col11` AS `col11`,`test000`.`col15` AS `col15`,`test000`.`col27` AS `col27` from `test000`; +CREATE ALGORITHM=UNDEFINED DEFINER=`example`@`localhost` SQL SECURITY DEFINER VIEW `test100` AS select `test000`.`id` AS `id`,`test000`.`col01` AS `col01`,`test000`.`col02` AS `col02`,`test000`.`col03` AS `col03`,`test000`.`col10` AS `col10`,`test000`.`col11` AS `col11`,`test000`.`col15` AS `col15`,`test000`.`col27` AS `col27` from `test000`; DROP VIEW IF EXISTS `test127`; -CREATE ALGORITHM=UNDEFINED DEFINER=`travis`@`localhost` SQL SECURITY DEFINER VIEW `test127` AS select `test027`.`id` AS `id`,`test027`.`col` AS `col` from `test027`; +CREATE ALGORITHM=UNDEFINED DEFINER=`example`@`localhost` SQL SECURITY DEFINER VIEW `test127` AS select `test027`.`id` AS `id`,`test027`.`col` AS `col` from `test027`; DROP TABLE IF EXISTS `test200`; diff --git a/tests/scripts/test006.src.sql b/tests/scripts/test006.src.sql index 66114667..f7af5800 100644 --- a/tests/scripts/test006.src.sql +++ b/tests/scripts/test006.src.sql @@ -72,7 +72,7 @@ CREATE TABLE IF NOT EXISTS `view_of_my_table` ( -- DROP TABLE IF EXISTS `my_view`; -CREATE ALGORITHM=UNDEFINED DEFINER=`travis`@`localhost` SQL SECURITY DEFINER VIEW `my_view` AS select `view_of_my_table`.`id` AS `id`,`view_of_my_table`.`name` AS `name`,`view_of_my_table`.`lastname` AS `lastname`,`view_of_my_table`.`username` AS `username` from `view_of_my_table`; +CREATE ALGORITHM=UNDEFINED DEFINER=`example`@`localhost` SQL SECURITY DEFINER VIEW `my_view` AS select `view_of_my_table`.`id` AS `id`,`view_of_my_table`.`name` AS `name`,`view_of_my_table`.`lastname` AS `lastname`,`view_of_my_table`.`username` AS `username` from `view_of_my_table`; -- -------------------------------------------------------- @@ -81,7 +81,7 @@ CREATE ALGORITHM=UNDEFINED DEFINER=`travis`@`localhost` SQL SECURITY DEFINER VIE -- DROP TABLE IF EXISTS `view_of_my_table`; -CREATE ALGORITHM=UNDEFINED DEFINER=`travis`@`localhost` SQL SECURITY DEFINER VIEW `view_of_my_table` AS select `my_table`.`id` AS `id`,`my_table`.`name` AS `name`,`my_table`.`lastname` AS `lastname`,`my_table`.`username` AS `username` from `my_table`; +CREATE ALGORITHM=UNDEFINED DEFINER=`example`@`localhost` SQL SECURITY DEFINER VIEW `view_of_my_table` AS select `my_table`.`id` AS `id`,`my_table`.`name` AS `name`,`my_table`.`lastname` AS `lastname`,`my_table`.`username` AS `username` from `my_table`; -- -- Índices para tablas volcadas diff --git a/tests/scripts/test010.8.src.sql b/tests/scripts/test010.8.src.sql index 265a032f..4f8e22fd 100644 --- a/tests/scripts/test010.8.src.sql +++ b/tests/scripts/test010.8.src.sql @@ -35,7 +35,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`travis`@`%`*/ /*!50106 EVENT `e_test010` ON SCHEDULE AT '2030-01-01 23:59:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO test010.test VALUES (NOW()) */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`example`@`%`*/ /*!50106 EVENT `e_test010` ON SCHEDULE AT '2030-01-01 23:59:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO test010.test VALUES (NOW()) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; diff --git a/tests/scripts/test010.src.sql b/tests/scripts/test010.src.sql index 21022843..169e9dfa 100644 --- a/tests/scripts/test010.src.sql +++ b/tests/scripts/test010.src.sql @@ -35,7 +35,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`travis`@`%`*/ /*!50106 EVENT `e_test010` ON SCHEDULE AT '2030-01-01 23:59:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO test010.test VALUES (NOW()) */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`example`@`%`*/ /*!50106 EVENT `e_test010` ON SCHEDULE AT '2030-01-01 23:59:00' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO test010.test VALUES (NOW()) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; diff --git a/tests/scripts/test011.src.sql b/tests/scripts/test011.src.sql deleted file mode 100644 index 1be17416..00000000 --- a/tests/scripts/test011.src.sql +++ /dev/null @@ -1,53 +0,0 @@ -DROP DATABASE IF EXISTS `test011`; -CREATE DATABASE `test011`; -USE `test011`; - --- MySQL dump 10.13 Distrib 5.7.15, for Linux (x86_64) --- --- Host: localhost Database: test --- ------------------------------------------------------ --- Server version 5.7.15 - -/*!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 */; - --- --- Table structure for table `test011` --- - -DROP TABLE IF EXISTS `test011`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `test011` ( - `id` int(11) NOT NULL, - `hash_stored` char(32) CHARACTER SET ascii COLLATE ascii_bin GENERATED ALWAYS AS (md5(`id`)) STORED NOT NULL, - `hash_virtual` char(32) CHARACTER SET ascii COLLATE ascii_bin GENERATED ALWAYS AS (md5(`id`)) VIRTUAL NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `test011` --- - -LOCK TABLES `test011` WRITE; -/*!40000 ALTER TABLE `test011` DISABLE KEYS */; -INSERT INTO `test011` (`id`) VALUES (159413),(294775); -/*!40000 ALTER TABLE `test011` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;