impactwave / mysql-tools
基于Laravel的Web应用程序中管理MySQL数据库的命令行shell脚本。
This package is auto-updated.
Last update: 2024-08-29 00:20:29 UTC
README
管理MySQL数据库的命令行shell脚本。
介绍
通过命令行备份、恢复和复制MySQL数据库并不像应该那样简单。大量的配置选项和边缘情况使你浪费大量时间在 Stack Overflow 上寻找答案,并且需要比应有的更多的工作。特别是如果服务器不在本地网络中,并且必须通过SSH隧道访问。
该项目提供了一组小的Bash脚本,使这些常见操作变得极其简单和容易。
注意:分支
laravel
(或任何1.x
版本)包含适用于与Laravel项目集成的旧版本。当前版本可以独立于任何项目或编程语言使用。你只需要在你的系统上安装 Bash。
它可以在你的计算机上全局安装,这样你就可以独立于任何数据库(本地或远程)使用提供的命令。
安装
独立安装
在电脑上的某个地方克隆仓库。
然后你可以
- 将这些文件复制到PATH上的一个文件夹中,或者
- 将项目的目录添加到你的环境的
PATH
变量中。
第二个选项的好处是,你可以通过发出 git pull
命令轻松地将工具更新到最新版本。
通过Composer安装
要全局安装到你的系统
composer global require impactwave/mysql-tools
如果你之前没有这样做,请将 ~/.composer/vendor/bin
添加到你的路径中,这样你就可以从电脑上的任何位置执行脚本。
示例
将其添加到你的shell环境(例如,在 ~/.profile
或 ~/.bash_profile
)中
export PATH=$PATH:./vendor/bin
仅在你的PHP项目中安装
将以下内容添加到我们的 composer.json
文件中
"require": {
"impactwave/mysql-tools": "^2.0"
},
或者,如果你想要最新的开发版本(不推荐)
"require": {
"impactwave/mysql-tools": "dev-master@dev"
},
注意:除非你想要这些工具的Laravel特定版本,否则不要检出
1.x
版本。
如果你之前没有这样做,请将 vendor/bin
添加到你的路径中,这样你就可以从项目的根目录执行脚本。
用法
mysql-backup
Backs up a MySQL database with sensible default options. Supports SSH connections to remote servers.
Usage: mysql-backup [options] [ssh://<ssh-user>@<ssh-host>[:<ssh-port>]]
[<mysql-user>:<mysql-pass>@<mysql-host>[:mysql-port]] <database> [<archive_name>]
Parameters:
ssh-user Username for the SSH connnection.
Note: you must use key-based SSH authentication; there is no option to specify a password.
ssh-host Hostname or IP address for the SSH connection.
ssh-port Port for SSH connnection. Defaults to 22.
mysql-user Username for database connection.
mysql-pass Password for database connection.
mysql-host Hostname or IP address for direct network connection to MySQL.
database Name of the database to be backed up.
archive_name Filename with optional path and without extension (.tgz or .sql will be appended).
If not specified or if it ends with / (it's a directory name), the backup archive will be named
'HOST-YYYY-MM-DD-hhmmss.tgz', where HOST is the target server's host name, YYYY-MM-DD is the current
date and hhmmss is the current time.
Options:
-t "<tables>" Space-delimited list of tables to be backed up (ex: -t "table1 table2").
-C Do not compress the backup; the backup file will be an SQL script instead of a compressed archive.
-D Do not set DEFINER clauses to the current user (which is done to prevent errors for missing users when
the backup is restored).
Notes:
- if no ssh:// connection argument is provided, a direct connection to MySQL will be performed.
- if no direct connection argument is provided, defaults will be used (localhost, current system user, current user's pass).
- if an compressed archive is generated, it will contain a file named '$dumpfile'.
- if using an SSH connection and -n is specified, the backup file will be copied to the local machine using network
compression.
许可证
MIT
MIT许可证(MIT)
版权所有 (c) 2014 Impactwave Lda
特此授予任何获得本软件及其相关文档文件(以下简称“软件”)副本的任何人,免费使用该软件的权利,不受限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许获得本软件的人进行此类操作,前提是以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和非侵权的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论此类索赔、损害或其他责任是基于合同、侵权或其他方式,无论是否因软件或其使用或其他方式而产生。