This repo contains an easy to use class to dump a database using PHP. Currently MySQL, PostgreSQL, SQLite and MongoDB are supported. Behindthe scenes mysqldump
, pg_dump
, sqlite3
and mongodump
are used.
Here's are simple examples of how to create a database dump with different drivers:
MySQL
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
PostgreSQL
Spatie\DbDumper\Databases\PostgreSql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
SQLite
Spatie\DbDumper\Databases\Sqlite::create()
->setDbName($pathToDatabaseFile)
->dumpToFile('dump.sql');
MongoDB
Spatie\DbDumper\Databases\MongoDb::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.gz');
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
For dumping MySQL-db's mysqldump
should be installed.
For dumping PostgreSQL-db's pg_dump
should be installed.
For dumping SQLite-db's sqlite3
should be installed.
For dumping MongoDB-db's mongodump
should be installed.
For compressing dump files, gzip
and/or bzip2
should be installed.
You can install the package via composer:
composer require spatie/db-dumper
This is the simplest way to create a dump of a MySql db:
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
If you're working with PostgreSQL just use that dumper, most methods are available on both the MySql. and PostgreSql-dumper.
Spatie\DbDumper\Databases\PostgreSql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
If the mysqldump
(or pg_dump
) binary is installed in a non default location you can let the package know by using thesetDumpBinaryPath()
-function:
Spatie\DbDumper\Databases\MySql::create()
->setDumpBinaryPath('/custom/location')
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
If your application is deployed and you need to change the host (default is 127.0.0.1), you can add the setHost()
-function:
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->setHost($host)
->dumpToFile('dump.sql');
Using an array:
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->includeTables(['table1', 'table2', 'table3'])
->dumpToFile('dump.sql');
Using a string:
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->includeTables('table1, table2, table3')
->dumpToFile('dump.sql');
In order to use "--column-statistics=0" as option in mysqldump command you can use doNotUseColumnStatistics() method.
If you have installed mysqldump 8, it queries by default column_statics table in information_schema database.In some old version of MySql (service) like 5.7, this table it not exists. So you could have an exception during the execution of mysqldump. To avoid this, you could use doNotUseColumnStatistics() method.
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->doNotUseColumnStatistics()
->dumpToFile('dump.sql');
Using an array:
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->excludeTables(['table1', 'table2', 'table3'])
->dumpToFile('dump.sql');
Using a string:
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->excludeTables('table1, table2, table3')
->dumpToFile('dump.sql');
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->doNotCreateTables()
->getDumpCommand('dump.sql', 'credentials.txt');
If you want to add an arbitrary option to the dump command you can use addExtraOption
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->addExtraOption('--xml')
->getDumpCommand('dump.sql', 'credentials.txt');
If you're working with MySql you can set the database name using --databases
as an extra option. This is particularly useful when used in conjunction with the --add-drop-database
mysqldump
option (see the mysqldump docs).
$dumpCommand = MySql::create()
->setUserName('username')
->setPassword('password')
->addExtraOption('--databases dbname')
->addExtraOption('--add-drop-database')
->getDumpCommand('dump.sql', 'credentials.txt');
With MySql, you also have the option to use the --all-databases
extra option. This is useful when you want to run a full backup of all the databases in the specified MySQL connection.
$dumpCommand = MySql::create()
->setUserName('username')
->setPassword('password')
->addExtraOption('--all-databases')
->getDumpCommand('dump.sql', 'credentials.txt');
Please note that using the ->addExtraOption('--databases dbname')
or ->addExtraOption('--all-databases')
will override the database name set on a previous ->setDbName()
call.
If you want the output file to be compressed, you can use a compressor class.
There are two compressors that come out of the box:
GzipCompressor
- This will compress your db dump with gzip
. Make sure gzip
is installed on your system before using this.Bzip2Compressor
- This will compress your db dump with bzip2
. Make sure bzip2
is installed on your system before using this.$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->useCompressor(new GzipCompressor()) // or `new Bzip2Compressor()`
->dumpToFile('dump.sql.gz');
You can create you own compressor implementing the Compressor
interface. Here's how that interface looks like:
namespace Spatie\DbDumper\Compressors;
interface Compressor
{
public function useCommand(): string;
public function useExtension(): string;
}
The useCommand
should simply return the compression command the db dump will get pumped to. Here's the implementation of GzipCompression
.
namespace Spatie\DbDumper\Compressors;
class GzipCompressor implements Compressor
{
public function useCommand(): string
{
return 'gzip';
}
public function useExtension(): string
{
return 'gz';
}
}
$ composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
Initial PostgreSQL support was contributed by Adriano Machado. SQlite support was contributed by Peter Matseykanets.
The MIT License (MIT). Please see License File for more information.
symfony/var-dumper字体大小设置 ###1、composer.json 中加载 symfony/var-dumper 类库 并在git中composer install后,发现 调试dump的时候 打印字体太小,于是找到以下文件: ####Path:项目根目录\vendor\symfony\var-dumper\Dumper\HtmlDumper.php 2、找到如下代码修改fon
前提条件:ios设备越狱,已安装ssh工具 1.Mac终端命令连接到设备上 ssh root@192.168.1.100(你的设备ip) mac-mini:~ ice$ ssh root@192.168.50.125 root@192.168.50.125's password: Icede-4s:~ root# 2.赋予Keychain数据库可读权限 Icede-4s:~ root# cd /
使用Keychain-Dumper导出keychain数据 iOS系统及第三方应用都会使用Keychain来作为数据持久化存储媒介,或者应用间数据共享的渠道。 所以Keychain数据库是hacker们最关注的数据源头之一。 不知道是算幸运还是不幸,导出Keychain数据库数据的工具早已非常完善,下载地址:Keychain-Dumper传送门 操作步骤极其简单: 1)赋予Keychain数据库可
初始化mysql数据库提示缺少Data:dumper模块解决方法 发布时间:2020-04-09 21:28:21 来源:51CTO 阅读:24680 作者:liuzhenlife 栏目:数据库 初始化mysql数据库时出现下面错误,原因是缺少Data:dumper模块[root@bogon mysql]# ./scripts/mysql_install_db --user=mysql FATAL
本文翻译自:Difference between rake db:migrate db:reset and db:schema:load The difference between rake db:migrate and rake db:reset is pretty clear in my head. rake db:migrate和rake db:reset之间的区别非常明显。 The th
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scri
1、iOS操作系统(包括mac),采用keychain数据库来存储敏感数据(例如wifi热点信息,邮箱信息等),keychain数据库位于iOS系统的/var/Keychains/keychain-2.db下,数据库中的内容是加密的,并且不同应用之间的数据存储是隔离的。 2、当打开这个数据库,会发现如下图中四个表:genp、inet、cert、keys 数据库内数据,大多数是加密的,Keychai
运行安装mysql 报错 [root@localhost mysql-mult]# ./scripts/mysql_install_db --defaults-file=conf/3306my.cnf FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db
db 跟数据库相关的操作。因为各项服务根本上的操作都需要跟数据库打交道,因此这部分定义了大量的数据库资源类和相关接口,可以被进一步继承实现。 包括对核心plugin api的实现基础类,其次是一些扩展的资源和方法的支持。 其中model_base.py和models_v2.py中定义了最基础的几个模型类。
基本使用 DB::connection('connection_name'); // 运行数据库查询语句 $results = DB::select('select * from users where id = ?', [1]); $results = DB::select('select * from users where id = :id', ['id' => 1]); // 运行普通语句
upper/db upper/db is a productive data access layer (DAL) for Gothat provides agnostic tools to work with different data sources, such as: PostgreSQL MySQL MSSQL CockroachDB MongoDB QL SQLite See uppe
这是一个小工具用来将 SQL Server 数据库转成 SQLite 数据库。
Apache Empire-db 是一个开源的关系型数据持久化组件,能够实现数据库无关的动态查询定义,简便的数据读取和更新。与其它持久化组件相比 如:Hibernate、TopLink、iBATIS或JPA实现,Empire-db更注重编译期类型安全,减少冗余,开发效率的改进。 Empire-db所有的数据库实体都通过动态bean进行管理,因此允许在运行期改变数据模型。
节点数据库 node-mdb是Amazon SimpleDB的基于Node.js的开源克隆 它是M / DB的重新实现,但是用Node.js Javascript重写。与M / DB一样,它使用免费的开源GT.M数据库作为数据存储库。 node-mdb是成熟的数据库,而不仅仅是模拟服务。 所有SimpleDB API均已实现,即: BatchDeleteAttributes BatchPutAtt
Dragonfly 是一个现代化的开源内存数据库,兼容 Redis 和 Memcached API,可作为两者的替代方案。与传统的内存数据存储相比,Dragonfly 提供了更高的吞吐量和缓存命中率、更低的尾延迟 (tail-latency),以及便捷的垂直可扩展性。 Dragonfly 在多线程、Shared-nothing 架构之上实现了全新的算法和数据结构,性能是 Redis 的 25 倍,
db-meta 是关系型数据库元数据获取工具,把数据库->schema->表->列,主键、外键、索引,触发器、存储过程、函数等抽象为对象,易于使用方便序列化。 1、 提供丰富的接口,能够获取常见的所有数据库元数据。DatabaseMeta和schemacrawler均不能很好的获取触发器、存储过程、函数的定义。 2、使用简单,比JDBC的DatabaseMeta易于使用,且不需要强制处