mysql自动化安装的shell脚本,二进制安装方式。
mysql的安装本就简单,此脚本省去了一下程序化的步骤。
使用方法:将mysql二进制安装包放在/apps目录下:
mysql:sh auto_install_mysql57.sh;
percona:sh auto_install_percona57.sh;
data目录为/data/mysql/mysql{$port},base目录为/apps/${mysql_version},可以根据需求修改。
版本限制:仅适用mysql5.16、percona5.16之后的版本。
执行前一定要配置好hosts文件!
mysql自动化安装脚本:
[root@mysql apps]# cat auto_install_mysql57.sh
#!/bin/bash
#usage:
#put the mysql tar package under /apps/
#the default datadir=/data/mysql/mysql${port},if you want a different,change it at line 146
#the default basedir=/apps/${mysql_version},if you want a different,change it at line 147
dt=`date`
c_date=`date '+%Y%m%d%H%M' '-d-0 day'`
host=`hostname`
echo "$dt"
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit 1
fi
clear
echo "====================================================================================="
echo "A tool to auto-compile & install MySQL 5.7.16 or later version on Redhat/CentOS Linux "
echo -e "=====================================================================================\n"
cur_dir=$(pwd)
#set mysql port
echo "===========================Set Mysql Port============================="
port="3306"
read -p "Set Mysql port (Press Enter for Default port: 3306):" port
if [ "${port}" = "" ]; then
port="3306"
fi
CMD0="ps -efl | grep -i "port=${port}" | grep -v grep"
sh -c "$CMD0" > /tmp/tmp_ps_mysql${port}.txt
while [ -s "/tmp/tmp_ps_mysql${port}.txt" ];do
read -p "A running MySQL process has already used port ${port}, please choose another one:" port
if [ "${port}" = "" ]; then
port="3306"
fi
CMD0="ps -efl | grep -i "port=${port}" | grep -v grep"
sh -c "$CMD0" > /tmp/tmp_ps_mysql${port}.txt
done
rm -f /tmp/tmp_ps_mysql${port}.txt
echo -e "MySQL port: ${port}\n"
#set mysql server_id
echo "=========================Set Mysql Server-id=========================="
read -p "mysql server_id (Press enter to generate a random server_id):" server_id
if test "${server_id}" = "" ;then
server_id=$RANDOM
fi
CMD1="ps -efl | grep "mysqld" | grep -v grep"
sh -c "$CMD1" > /tmp/tmp_ps_mysql_serverid.txt
cat /tmp/tmp_ps_mysql_serverid.txt | sed -r 's/.*defaults-file=(.*).cnf.*/\1/' > /tmp/tmp1_ps_mysql_serverid.txt
touch /tmp/exsists_server_id.txt
while read mycnf
do
cat $mycnf.cnf | grep -i server-id | awk 'BEGIN{FS="="}{print $2}' >> /tmp/exsists_server_id.txt
done < /tmp/tmp1_ps_mysql_serverid.txt
for line in `cat /tmp/exsists_server_id.txt`
do
if test "$line" = "$server_id" ;then
read -p "this server_id has been used by an running mysql, Please choose another server_id: " server_id
if test "$line" = "$server_id" ;then
read -p "this server_id has been used by an running mysql, Please choose another server_id: " server_id
if test "$line" = "$server_id" ;then
server_id=$RANDOM
echo "Exsist again, I lost my patience, generate a random server_id: $server_id"
fi
fi
fi
done
rm -f /tmp/tmp_ps_mysql_serverid.txt /tmp/tmp1_ps_mysql_serverid.txt /tmp/exsists_server_id.txt
echo -e "MySQL server_id: ${server_id}\n"
#set mysql root password
echo "=======================Set Mysql Root Password========================"
mysqlrootpwd="mypasswd"
read -p "Set Mysql Root Password (Press Enter for Default password: mypasswd):" mysqlrootpwd
if [ "${mysqlrootpwd}" = "" ]; then
mysqlrootpwd="mypasswd"
fi
echo -e "MySQL root password:${mysqlrootpwd}\n"
#which MySQL Version do you want to install?
echo "========================Check MySQL Version==========================="
cd /apps/
myversion=`ls mysql-5.7.*linux*.tar.gz`
mysql_version=`expr substr $myversion 7 6`
isinstallmysql57="n"
echo "Install MySQL ${mysql_version}, Please input:y"
echo "If Not This Version, Please input:n"
read -p "Please input y , n (Press Enter for Version ${mysql_version}):" isinstallmysql57
case "$isinstallmysql57" in
y|Y|Yes|YES|yes|yES|yEs|YeS|yeS|"")
echo "You will install MySQL ${mysql_version}"
isinstallmysql57="y"
;;
*)
echo "INPUT error,You will exit install MySQL ${mysql_version}"
isinstallmysql57="n"
exit
esac
#Initialize the installation related content
echo -e "\n==============Initialize the installation related content============="
echo -e "OS version:"
uname -r
MemTotal=`free -m | grep Mem | awk '{print $2}'`
echo -e "\nMemory is: $MemTotal MB "
echo -e "\nDelete Old Mysql program"
rpm -qa|grep mysql
rpm -e mysql
echo -e "\nDisable SeLinux"
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
setenforce 0
cd $cur_dir
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
#Install MySQL
echo -e "\n========================Install MySQL ${mysql_version}=========================="
datadir=/data/mysql/mysql${port}
basedir=/apps/mysql${mysql_version}
#mysql directory configuration
echo -e "unzip $myversion\nThis may take a few minutes!"
if [ -d /apps/mysql-${mysql_version}-linux*x86_64 ]; then
echo "Tar package already unziped! Continue the next step"
if [ ! -d /apps/mysql${mysql_version} ]; then
mv /apps/mysql-${mysql_version}-linux*x86_64 ${basedir}
fi
elif [ -d /apps/mysql${mysql_version} ]; then
echo -e "\nDirectory /apps/mysql${mysql_version} already Exsists!\nSkipped unzip, Continue the next step...\n"
else
cd /apps
tar xf /apps/$myversion -C /apps/
echo -e "unzip completed!\n"
mv /apps/mysql-${mysql_version}-linux*x86_64 ${basedir}
fi
##Create User Mysql
id mysql
if [ $? -ne 0 ]; then
echo -e "Create User Mysql ..."
groupadd mysql -g 512
useradd -u 512 -g mysql -s /sbin/nologin -d /home/mysql mysql
else
echo -e "User Mysql has bean created by other one!\n"
fi
#mysql directory configuration
if [ -d /data/mysql/mysql${port} ]; then
if [ "`ls -A /data/mysql/mysql${port}`" = "" ]; then
echo "/data/mysql/mysql${port} exsists and is not empty"
echo "Please drop or empty it and run the script again!"
exit 0
else
echo "/data/mysql/mysql${port} created by other one!"
fi
else
echo -e "Create data directory /data/mysql/mysql${port}...\n"
mkdir -p /data/mysql/mysql${port}
fi
chown -R mysql:mysql ${basedir}
chown -R mysql:mysql ${datadir}
echo -e "Link ${basedir} to /usr/local/mysql..."
if [ -L /usr/local/mysql ];then
echo "/usr/local/mysql already been linked, skiped! Continue..."
else
ln -s ${basedir} /usr/local/mysql
fi
#server_id=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'`
#generate mysql.cnf file
cat >>${datadir}.cnf<< EOF
[client]
port=${port}
socket=/tmp/mysql_${port}.sock
default-character-set=utf8
[mysql]
port=${port}
socket=/tmp/mysql_${port}.sock
default-character-set=utf8
[mysqld]
port=${port}
character-set-server=utf8
socket=/tmp/mysql_${port}.sock
basedir=${basedir}
datadir=${datadir}
explicit_defaults_for_timestamp=true
federated
#lower_case_table_names=1
back_log=150
max_connections=3000
max_connect_errors=10
table_open_cache=2048
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=8M
join_buffer_size=8M
thread_cache_size=8
query_cache_size=512M
query_cache_limit=4M
transaction_isolation=REPEATABLE-READ
tmp_table_size=96M
max_heap_table_size=96M
###***slow query parameters
long_query_time=1
slow_query_log = 1
slow_query_log_file=${datadir}/slow.log
###***binlog parameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
binlog_format=statement
expire_logs_days=30
###***relay-log parameters
#relay-log=/data/3307/relay-bin
#relay-log-info-file=/data/3307/relay-log.info
#master-info-repository=table
#relay-log-info-repository=table
#relay-log-recovery=1
#***MyISAM parameters
key_buffer_size=32M
read_buffer_size=2M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
myisam_sort_buffer_size = 16M
myisam_max_sort_file_size = 16M
myisam_repair_threads = 1
skip-name-resolve
###***master-slave replication parameters
server-id=${server_id}
#slave-skip-errors=all
#***Innodb storage engine parameters
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
#innodb_file_io_threads=8
#innodb_thread_concurrency=16
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=3
innodb_max_dirty_pages_pct=90
innodb_buffer_pool_dump_pct=90
innodb_lock_wait_timeout=2
innodb_file_per_table=on
[mysqldump]
quick
max_allowed_packet=32M
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
[mysqld_safe]
open-files-limit=8192
#log-error=/data/mysql/error.log
#pid-file=/data/mysql/mysqld.pid
EOF
#Initialize Data
echo -e "\n===========================Initialize Data============================"
${basedir}/bin/mysqld --defaults-file=${datadir}.cnf --user=mysql --datadir=${datadir} --basedir=${basedir} --initialize-insecure > /dev/null 2>&1
echo -e "Completed!"
cp ${basedir}/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
cat >> /etc/ld.so.conf.d/mysql-x86_64.conf<<EOF
/usr/local/mysql/lib
EOF
ldconfig
if [ -d "/proc/vz" ];then
ulimit -s unlimited
fi
#Start Mysql Database
echo -e "\n=========================Start Mysql Database========================="
nohup ${basedir}/bin/mysqld_safe --defaults-file=${datadir}.cnf & > /dev/null 2>&1
sleep 5s
sleep 5s
echo -e "Completed!\n"
sleep 10s
#Check the install
echo "============================Check install============================="
echo "Check mysql process"
rm -f /tmp/mysql_${port}.sock.lock nohup.out
CMD1="ps -efl | grep -i "port=${port}" | grep -v grep"
sh -c "$CMD1" > /tmp/ps_mysql${port}.txt
if [ -s "/tmp/ps_mysql${port}.txt" ];
then
echo -e "\ninstallation success!\nlog located at ${datadir}/${host}.err\n"
rm -f /tmp/ps_mysql${port}.txt
else
echo -e "\ninstall failed!\ncheck the err log: ${datadir}/${host}.err\n"
exit 0
fi
#Set The Environmental variables
cat >> /etc/profile <<EOF
export PATH=$PATH:${basedir}/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${basedir}/lib
EOF
cat >> ~/.bashrc <<EOF
alias mysql${port}='${basedir}/bin/mysql -uroot -p -S /tmp/mysql_${port}.sock'
EOF
source ~/.bashrc
#change mysql root password
echo "=====================change mysql root password======================="
cat > /tmp/mysql_sec_script.sql<<EOF
use mysql;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${mysqlrootpwd}');
grant all privileges on *.* to root@'%' identified by '${mysqlrootpwd}';
flush privileges;
EOF
${basedir}/bin/mysql -u root -S /tmp/mysql_${port}.sock < /tmp/mysql_sec_script.sql
echo -e "mysql root password changed!\n"
rm -f /tmp/mysql_sec_script.sql
echo -e "Execute this command first: source ~/.bashrc\nThen you can enter your mysql database using alias mysql${port}!\n"
echo -e "${dt}\n"
percona自动化安装脚本:
[root@percona apps]# cat auto_install_percona57.sh
#!/bin/bash
#usage:
#put the mysql tar package under /apps/
#the default datadir=/data/mydata/mysql${port},if you want a different,change it at line 146
#the default basedir=/apps/${mysql_version},if you want a different,change it at line 147
dt=`date`
c_date=`date '+%Y%m%d%H%M' '-d-0 day'`
host=`hostname`
echo "$dt"
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install"
exit 1
fi
clear
echo "====================================================================================="
echo "A tool to auto-compile & install Percona 5.7.16 or later version on Redhat/CentOS Linux "
echo -e "=====================================================================================\n"
cur_dir=$(pwd)
#set mysql port
echo "===========================Set Mysql Port============================="
port="3306"
read -p "Set Mysql port (Press Enter for Default port: 3306):" port
if [ "${port}" = "" ]; then
port="3306"
fi
CMD0="ps -efl | grep -i "port=${port}" | grep -v grep"
sh -c "$CMD0" > /tmp/tmp_ps_mysql${port}.txt
while [ -s "/tmp/tmp_ps_mysql${port}.txt" ];do
read -p "A running MySQL process has already used port ${port}, please choose another one:" port
if [ "${port}" = "" ]; then
port="3306"
fi
CMD0="ps -efl | grep -i "port=${port}" | grep -v grep"
sh -c "$CMD0" > /tmp/tmp_ps_mysql${port}.txt
done
rm -f /tmp/tmp_ps_mysql${port}.txt
echo -e "MySQL port: ${port}\n"
#set mysql server_id
echo "=========================Set Mysql Server-id=========================="
read -p "mysql server_id (Press enter to generate a random server_id):" server_id
if test "${server_id}" = "" ;then
server_id=$RANDOM
fi
CMD1="ps -efl | grep "mysqld" | grep -v grep"
sh -c "$CMD1" > /tmp/tmp_ps_mysql_serverid.txt
cat /tmp/tmp_ps_mysql_serverid.txt | sed -r 's/.*defaults-file=(.*).cnf.*/\1/' > /tmp/tmp1_ps_mysql_serverid.txt
touch /tmp/exsists_server_id.txt
while read mycnf
do
cat $mycnf.cnf | grep -i server-id | awk 'BEGIN{FS="="}{print $2}' >> /tmp/exsists_server_id.txt
done < /tmp/tmp1_ps_mysql_serverid.txt
for line in `cat /tmp/exsists_server_id.txt`
do
if test "$line" = "$server_id" ;then
read -p "this server_id has been used by an running mysql, Please choose another server_id: " server_id
if test "$line" = "$server_id" ;then
read -p "this server_id has been used by an running mysql, Please choose another server_id: " server_id
if test "$line" = "$server_id" ;then
server_id=$RANDOM
echo "Exsist again, I lost my patience, generate a random server_id: $server_id"
fi
fi
fi
done
rm -f /tmp/tmp_ps_mysql_serverid.txt /tmp/tmp1_ps_mysql_serverid.txt /tmp/exsists_server_id.txt
echo -e "MySQL server_id: ${server_id}\n"
#set mysql root password
echo "=======================Set Mysql Root Password========================"
mysqlrootpwd="mypasswd"
read -p "Set Mysql Root Password (Press Enter for Default password: mypasswd):" mysqlrootpwd
if [ "${mysqlrootpwd}" = "" ]; then
mysqlrootpwd="mypasswd"
fi
echo -e "MySQL root password:${mysqlrootpwd}\n"
#which MySQL Version do you want to install?
echo "========================Check MySQL Version==========================="
cd /apps/
myversion=`ls Percona*5.7.*Linux*.tar.gz`
echo $myversion > /tmp/version.txt
sed -i 's/.tar.gz//' /tmp/version.txt
mysqlversion=`cat /tmp/version.txt`
mysql_version=`expr substr $myversion 16 6`
isinstallmysql57="n"
echo "Install MySQL ${mysql_version}, Please input:y"
echo "If Not This Version, Please input:n"
read -p "Please input y , n (Press Enter for Version ${mysql_version}):" isinstallmysql57
case "$isinstallmysql57" in
y|Y|Yes|YES|yes|yES|yEs|YeS|yeS|"")
echo "You will install MySQL ${mysql_version}"
isinstallmysql57="y"
;;
*)
echo "INPUT error,You will exit install MySQL ${mysql_version}"
isinstallmysql57="n"
exit
esac
#Initialize the installation related content
echo -e "\n==============Initialize the installation related content============="
echo -e "OS version:"
uname -r
MemTotal=`free -m | grep Mem | awk '{print $2}'`
echo -e "\nMemory is: $MemTotal MB "
echo -e "\nDelete Old Mysql program"
rpm -qa|grep mysql
rpm -e mysql
echo -e "\nDisable SeLinux"
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
setenforce 0
cd $cur_dir
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
#Install MySQL
echo -e "\n========================Install MySQL ${mysql_version}=========================="
datadir=/data/mydata/mysql${port}
basedir=/apps/mysql${mysql_version}
#mysql directory configuration
echo -e "unzip $myversion\nThis may take a few minutes!"
if [ -d /apps/${mysqlversion} ]; then
echo "Tar package already unziped! Continue the next step"
if [ ! -d /apps/mysql${mysql_version} ]; then
mv /apps/${mysqlversion} ${basedir}
fi
elif [ -d /apps/mysql${mysql_version} ]; then
echo -e "\nDirectory /apps/mysql${mysql_version} already Exsists!\nSkipped unzip, Continue the next step...\n"
else
cd /apps
tar xf /apps/$myversion -C /apps/
echo -e "unzip completed!\n"
mv /apps/${mysqlversion} ${basedir}
fi
##Create Mysql user
id mysql
if [ $? -ne 0 ]; then
echo -e "Create User Mysql ..."
groupadd mysql -g 512
useradd -u 512 -g mysql -s /sbin/nologin -d /home/mysql mysql
else
echo -e "User Mysql has bean created by other one!\n"
fi
#mysql directory configuration
if [ -d /data/mydata/mysql${port} ]; then
if [ "`ls -A /data/mydata/mysql${port}`" = "" ]; then
echo "/data/mydata/mysql${port} exsists and is not empty"
echo "Please drop or empty it and run the script again!"
exit 0
else
echo "/data/mydata/mysql${port} created by other one!"
fi
else
echo -e "Create data directory /data/mydata/mysql${port}...\n"
mkdir -p /data/mydata/mysql${port}
fi
chown -R mysql:mysql ${basedir}
chown -R mysql:mysql ${datadir}
echo -e "Link ${basedir} to /usr/local/mysql..."
if [ -L /usr/local/mysql ];then
echo "/usr/local/mysql already been linked, skiped! Continue..."
else
ln -s ${basedir} /usr/local/mysql
fi
#server_id=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'`
#generate mysql.cnf file
cat >>${datadir}.cnf<< EOF
[client]
port=${port}
socket=/tmp/mysql_${port}.sock
default-character-set=utf8
[mysql]
port=${port}
socket=/tmp/mysql_${port}.sock
default-character-set=utf8
[mysqld]
port=${port}
character-set-server=utf8
socket=/tmp/mysql_${port}.sock
basedir=${basedir}
datadir=${datadir}
explicit_defaults_for_timestamp=true
federated
#lower_case_table_names=1
back_log=150
max_connections=3000
max_connect_errors=10
table_open_cache=2048
external-locking=FALSE
max_allowed_packet=32M
sort_buffer_size=8M
join_buffer_size=8M
thread_cache_size=8
query_cache_size=512M
query_cache_limit=4M
transaction_isolation=REPEATABLE-READ
tmp_table_size=96M
max_heap_table_size=96M
###***slow query parameters
long_query_time=1
slow_query_log = 1
slow_query_log_file=${datadir}/slow.log
###***binlog parameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
binlog_format=statement
expire_logs_days=30
###***relay-log parameters
#relay-log=/data/3307/relay-bin
#relay-log-info-file=/data/3307/relay-log.info
#master-info-repository=table
#relay-log-info-repository=table
#relay-log-recovery=1
#***MyISAM parameters
key_buffer_size=32M
read_buffer_size=2M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
myisam_sort_buffer_size = 16M
myisam_max_sort_file_size = 16M
myisam_repair_threads = 1
skip-name-resolve
###***master-slave replication parameters
server-id=${server_id}
#slave-skip-errors=all
#***Innodb storage engine parameters
innodb_buffer_pool_size=512M
innodb_data_file_path=ibdata1:10M:autoextend
#innodb_file_io_threads=8
#innodb_thread_concurrency=16
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=3
innodb_max_dirty_pages_pct=90
innodb_buffer_pool_dump_pct=90
innodb_lock_wait_timeout=2
innodb_file_per_table=on
[mysqldump]
quick
max_allowed_packet=32M
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
[mysqld_safe]
open-files-limit=8192
#log-error=/data/mydata/error.log
#pid-file=/data/mydata/mysqld.pid
EOF
#Initialize Data
echo -e "\n===========================Initialize Data============================"
${basedir}/bin/mysqld --user=mysql --datadir=${datadir} --basedir=${basedir} --initialize-insecure > /dev/null 2>&1
echo -e "Completed!"
cp ${basedir}/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
cat >> /etc/ld.so.conf.d/mysql-x86_64.conf<<EOF
/usr/local/mysql/lib
EOF
ldconfig
if [ -d "/proc/vz" ];then
ulimit -s unlimited
fi
#Start Mysql Database
echo -e "\n=========================Start Mysql Database========================="
nohup ${basedir}/bin/mysqld_safe --defaults-file=${datadir}.cnf & > /dev/null 2>&1
sleep 5s
sleep 5s
echo -e "Completed!\n"
sleep 10s
#Check the install
echo "============================Check install============================="
echo "Check mysql process"
rm -f /tmp/mysql_${port}.sock.lock nohup.out
CMD1="ps -efl | grep -i "port=${port}" | grep -v grep"
sh -c "$CMD1" > /tmp/ps_mysql${port}.txt
if [ -s "/tmp/ps_mysql${port}.txt" ];
then
echo -e "\ninstallation success!\nlog located at ${datadir}/${host}.err\n"
rm -f /tmp/ps_mysql${port}.txt
else
echo -e "\ninstall failed!\ncheck the err log: ${datadir}/${host}.err\n"
exit 0
fi
#Set The Environmental variables
cat >> /etc/profile <<EOF
export PATH=$PATH:${basedir}/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${basedir}/lib
EOF
cat >> ~/.bashrc <<EOF
alias mysql${port}='${basedir}/bin/mysql -uroot -p -S /tmp/mysql_${port}.sock'
EOF
source ~/.bashrc
#change mysql root password
echo "=====================change mysql root password======================="
cat > /tmp/mysql_sec_script.sql<<EOF
use mysql;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${mysqlrootpwd}');
grant all privileges on *.* to root@'%' identified by '${mysqlrootpwd}';
flush privileges;
EOF
${basedir}/bin/mysql -u root -S /tmp/mysql_${port}.sock < /tmp/mysql_sec_script.sql
echo -e "mysql root password changed!\n"
rm -f /tmp/mysql_sec_script.sql /tmp/version.txt
echo -e "Execute this command first: source ~/.bashrc\nThen you can enter your mysql database using alias mysql${port}!\n"
echo -e "${dt}\n"