Last active
March 8, 2017 14:58
-
-
Save davidalves1/b14f294010d82151086bd672ba864d20 to your computer and use it in GitHub Desktop.
Script para alterar o charset e collation da tabela de Latin1 para utf-8 no windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo OFF | |
echo Eh preciso baixar e instalar o SED antes de continuar: https://sourceforge.net/projects/gnuwin32/files//sed/4.2.1/sed-4.2.1-setup.exe/download | |
pause | |
echo ==================== | |
echo Realizando backup do banco em 'C:\Users\(seu-usuario)' | |
set hour=%time:~0,2% | |
if "%hour:~0,1%" == " " set hour=0%hour:~1,1% | |
set min=%time:~3,2% | |
if "%min:~0,1%" == " " set min=0%min:~1,1% | |
set secs=%time:~6,2% | |
if "%secs:~0,1%" == " " set secs=0%secs:~1,1% | |
set old_db_name=my_old_database_name | |
set new_db_name=my_new_database_name | |
set backup=bak-%date:~6,4%%date:~3,2%%date:~0,2%-%hour%%min%%secs%.sql | |
mysqldump -h localhost -u root -v --single-transaction %old_db_name% > %USERPROFILE%\%backup% | |
echo CREATE DATABASE IF NOT EXISTS `%new_db_name%` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; > create_utf8_db.sql | |
mysql -h localhost -u root < create_utf8_db.sql | |
echo ==================== | |
echo Copia o schema do banco de dados atual para o novo alterando o charset de Latin1 para utf8 | |
mysqldump -h localhost -u root %old_db_name% -v --single-transaction --no-data --skip-set-charset --default-character-set=latin1 | sed -e s/CHARSET=latin1/CHARSET=utf8/g | mysql -h localhost -u root %new_db_name% --default-character-set=utf8 | |
echo ==================== | |
echo Passa os dados do banco atual para o novo | |
mysqldump -h localhost -u root -v --no-create-db --single-transaction --no-create-info --skip-set-charset --default-character-set=latin1 %old_db_name% | mysql -h localhost -u root %new_db_name% --default-character-set=utf8 | |
echo Sucesso! :) | |
del create_utf8_db.sql | |
pause | |
@echo ON |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment