<commit_before>#!/bin/bash
# Migrate an MySQL based database including the user who have access to another
# host. Have also the possibility to use an ssh tunnel.

script_path=$(dirname $(readlink -f $BASH_SOURCE))
temp_file=$(mktemp)

# Read configuration file
[[ -f ${script_path}/mysql-migrate-db.conf.sh ]] \
	&& source ${script_path}/mysql-migrate-db.conf.sh

# Functions
function die() {
	retval=${1}; shift
	if [[ ${#} -gt 0 ]]; then
		echo "error: ${@}"
	fi
	rm ${temp_file}
	exit ${retval:-1}
}
function usage() {
	echo "${0} [sql_db] [sql_user]"
	die 0
}

# Verify variable settings
if [ -z "${src_host}" ] || [ -z "${src_user}" ] || [ -z "${src_pass}" ] || \
   [ -z "${dst_host}" ] || [ -z "${dst_user}" ] || [ -z "${dst_pass}" ]; then
	die 1 "Please make sure all config variables are set correctly"
fi
if [ -n "${ssh_host}" ] && [ -n "${ssh_user}" ]; then
	ssh_dst="${ssh_user}@${ssh_host}"
fi

# Input parameter
sql_db=${1}
sql_user=${2}

if [ -z "${sql_db}" ] || [ -z "${sql_user}" ]; then
	usage
fi

# Check source MySQL server connection
if ! mysqladmin --host="${src_host}" --user="${src_user}" \
                --password="${src_pass}" ping &>/dev/null; then
	die 2 "Couldn't connection to source MySQL server"
fi

# Be sure database you like to migrate exists on the source
if ! mysql --host="${src_host}" --user="${src_user}" --password="${src_<PASSWORD>}" \
           -N -B  -e"show databases;" | grep -q "^${sql_db}$"; then
	die 3 "Database doesn't exists on source MySQL server"
fi

# Create DB and user information into temp file
echo "*** create temp file with database creation and permission"
echo "CREATE DATABASE IF NOT EXISTS ${sql_db};" >> ${temp_file}<commit_msg>Use apostrophe for database name, to have valid db names with hyphens<commit_after>#!/bin/bash
# Migrate an MySQL based database including the user who have access to another
# host. Have also the possibility to use an ssh tunnel.

script_path=$(dirname $(readlink -f $BASH_SOURCE))
temp_file=$(mktemp)

# Read configuration file
[[ -f ${script_path}/mysql-migrate-db.conf.sh ]] \
	&& source ${script_path}/mysql-migrate-db.conf.sh

# Functions
function die() {
	retval=${1}; shift
	if [[ ${#} -gt 0 ]]; then
		echo "error: ${@}"
	fi
	rm ${temp_file}
	exit ${retval:-1}
}
function usage() {
	echo "${0} [sql_db] [sql_user]"
	die 0
}

# Verify variable settings
if [ -z "${src_host}" ] || [ -z "${src_user}" ] || [ -z "${src_pass}" ] || \
   [ -z "${dst_host}" ] || [ -z "${dst_user}" ] || [ -z "${dst_pass}" ]; then
	die 1 "Please make sure all config variables are set correctly"
fi
if [ -n "${ssh_host}" ] && [ -n "${ssh_user}" ]; then
	ssh_dst="${ssh_user}@${ssh_host}"
fi

# Input parameter
sql_db=${1}
sql_user=${2}

if [ -z "${sql_db}" ] || [ -z "${sql_user}" ]; then
	usage
fi

# Check source MySQL server connection
if ! mysqladmin --host="${src_host}" --user="${src_user}" \
                --password="${src_pass}" ping &>/dev/null; then
	die 2 "Couldn't connection to source MySQL server"
fi

# Be sure database you like to migrate exists on the source
if ! mysql --host="${src_host}" --user="${src_user}" --password="${<PASSWORD>}" \
           -N -B  -e"show databases;" | grep -q "^${sql_db}$"; then
	die 3 "Database doesn't exists on source MySQL server"
fi

# Create DB and user information into temp file
echo "*** create temp file with database creation and permission"
echo "CREATE DATABASE IF NOT EXISTS \`${sql_db}\`;" >> ${temp_file}
{'fraction_non_alphanumeric': 0.185002895193978, 'fraction_numerical': 0.005790387955993051, 'mean_word_length': 3.838935574229692, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3581770', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1158, 'n_words': 390}