Exporting Database to file
Windows
- From an administrative Powershell window, execute the commands below to export your database to a file
echo "Stopping MySQL daemon and MySQL service..."
mysqld -u root stop #stop daemon
net stop MySQL # stop service
echo "Fetching name of wordpress database..."
$hash=[Math]::Round((Get-Date).ToFileTime()/10000) # create uid
$databaseMetaData="database-$hash.sql" # create file name
bash -c "echo `$`(sed -n `"s/define( *'DB_NAME', *'\([^']*\)'.*/\1/p`" wp-config.php) > $databaseMetaData" # append database name to metadata file
$databaseName=Get-Content -Path $databaseMetaData -TotalCount 1 # fetch first line of metadata file
del $databaseMetaData # deleting metadata
echo "Dumping data..."
mysqld -u root start # starting daemon
net start MySQL # starting service
mysqldump -uroot -p $databaseName > databaseBackUp.sql # dumping database to file
Mac OS
databaseName=$(sed -n "s/define( *'DB_NAME', *'\([^']*\)'.*/\1/p" wp-config.php)
echo "Dumping data..."
mysqld -u root start # starting daemon
net start MySQL # starting service
mysqldump -uroot -p $databaseName > databaseBackUp.sql # dumping database to file
Linux