This repository has been archived on 2024-11-07. You can view files and clone it, but cannot push or open issues or pull requests.
mysql51/mysql_convert_db_format_to_mysql41.sh

51 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/bash
# $0 -- Convert all local MySQL DB to the MySQL 4.1 format
# Copyright (C) 2005 Davide Madrisan <davide.madrisan@qilinux.it>
# see: http://dev.mysql.com/doc/mysql/en/upgrading-from-4-0.html
[ $UID = 0 ] ||
{ echo "error: ${0##*/}: must be superuser" >&2; exit 1; }
# dump all local MySQL DB to a temporary file
tempf=`mktemp -t allMySQLdb.XXXXXX` ||
{ echo "cannot create secure temporary files." >&2; exit 1; }
trap 'rm -f $tempf' 0 1 2 3 6 7 13 15
[ -f /var/lock/subsys/mysql ] &&
let "mysql_is_running = 1" || let "mysql_is_running = 0"
[ "$mysql_is_running" = "1" ] ||
{ service mysql start; sleep 3; }
echo "dumping all MySQL DB to $tempf..."
mysqldump --all-databases --result-file=$tempf >/dev/null
service mysql stop
sleep 3
# create a backup copy of all mysql DB
echo "creating a backup copy of all the DB in $bckdir..."
bckdir=`mktemp -d /var/lib/mysql.XXXXXX` ||
{ echo "cannot create a backup copy of local MySQL db." >&2; exit 1; }
mv /var/lib/mysql/ $bckdir
echo "creating a new MySQL DB and change permissions..."
install -d -m755 -o mysql -g mysql /var/lib/mysql/
mysql_install_db -b /usr --ldata=/var/lib/mysql
/bin/chown -R mysql.mysql /var/lib/mysql/*
service mysql start
sleep 3
echo "restoring the dumped MySQL DB $tempf..."
mysql < $tempf
#mysql_fix_privilege_tables
rm -f $tempf
[ "$mysql_is_running" = "1" ] || service mysql stop