Berikut file windows bat yang saya tulis yang menggabungkan saran Vincent dan Pauls. Ini meminta pengguna untuk nama sumber dan tujuan.
Cukup ubah variabel di bagian atas untuk menyetel jalur yang tepat ke port executable / database Anda.
:: Creates a copy of a database with a different name.
:: User is prompted for Src and destination name.
:: Fair Warning: passwords are passed in on the cmd line, modify the script with -p instead if security is an issue.
:: Uncomment the rem'd out lines if you want script to prompt for database username, password, etc.
:: See also: http://stackoverflow.com/questions/1887964/duplicate-entire-mysql-database
@set MYSQL_HOME="C:\sugarcrm\mysql\bin"
@set mysqldump_exec=%MYSQL_HOME%\mysqldump
@set mysql_exec=%MYSQL_HOME%\mysql
@set SRC_PORT=3306
@set DEST_PORT=3306
@set USERNAME=TODO_USERNAME
@set PASSWORD=TODO_PASSWORD
:: COMMENT any of the 4 lines below if you don't want to be prompted for these each time and use defaults above.
@SET /p USERNAME=Enter database username:
@SET /p PASSWORD=Enter database password:
@SET /p SRC_PORT=Enter SRC database port (usually 3306):
@SET /p DEST_PORT=Enter DEST database port:
%MYSQL_HOME%\mysql
@IF NOT "%ERRORLEVEL%" == "0" GOTO ExitScript
@SET /p SRC_DB=What is the name of the SRC Database:
@SET /p DEST_DB=What is the name for the destination database (that will be created):
%mysql_exec%
%mysqldump_exec%
@echo SUCCESSFUL!!!
@GOTO ExitSuccess
:ExitScript
@echo "Failed to copy database"
:ExitSuccess
Output sampel:
C:\sugarcrm_backups\SCRIPTS>copy_db.bat
Enter database username: root
Enter database password: MyPassword
Enter SRC database port (usually 3306): 3308
Enter DEST database port: 3308
C:\sugarcrm_backups\SCRIPTS>"C:\sugarcrm\mysql\bin"\mysql
+
| Database |
+
| information_schema |
| mysql |
| performance_schema |
| sugarcrm_550_pro |
| sugarcrm_550_ce |
| sugarcrm_640_pro |
| sugarcrm_640_ce |
+
What is the name of the SRC Database: sugarcrm
What is the name for the destination database (that will be created): sugarcrm_640_ce
C:\sugarcrm_backups\SCRIPTS>"C:\sugarcrm\mysql\bin"\mysql
C:\sugarcrm_backups\SCRIPTS>"C:\sugarcrm\mysql\bin"\mysqldump
SUCCESSFUL!!!