#!/bin/bash


mysql_pwd.py eole21
DATABASES=`mysql -u root -peole21 -e 'use mysql; select Db  from db where Db NOT IN ("performance_schema", "mysql","information_schema","sys");' |awk '!/Db/ {print $NF}'|sort|uniq`
mysqldump -hlocalhost -uroot -peole21 --databases $DATABASES > dump.sql

for database in $DATABASES;do
    mysql -u root -peole21 -e "drop database $database;"
done

#to avoid "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded"
mysql -uroot -peole21 -e "use mysql; update user set authentication_string=PASSWORD('eole21') where User='root';"
mysql -uroot -peole21 -e 'use mysql; update user set plugin="mysql_native_password";flush privileges;'

systemctl stop mysql.service

cat > /etc/mysql/mysql.conf.d/mysqld_innodb.cnf << EOF
[mysqld]
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_log_file_size=1G
innodb_buffer_pool_size=4G

EOF

rm -rf /var/lib/mysql/{ibdata1,ib_logfile0,ib_logfile1}

systemctl start mysql.service

mysql -uroot -peole21 < dump.sql
