erplibre/script/database/restore_mariadb_sql_example_1.sh
Mathieu Benoit 24e5cba22b [UPD] makefile: improve test
- prevent makefile cache to ignore test
- update image_db_create_erplibre_base
- add mariadb migrator test
- add helloworld test
- fix other test
- add isort format
- add show log of test
- add clean to remove temporary file
2022-01-24 14:09:17 -05:00

29 lines
886 B
Bash
Executable file

#!/usr/bin/env bash
SQL_PATH=./script/database/mariadb_sql_example_1.sql
# You need to set no password to mysql root user
# SET PASSWORD FOR root@localhost='';
# FLUSH PRIVILEGES;
# Second solution
# ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
# FLUSH PRIVILEGES;
echo "Create database and user"
mysql -u root << EOF
DROP DATABASE IF EXISTS mariadb_sql_example_1;
CREATE USER IF NOT EXISTS 'organization'@'localhost' IDENTIFIED BY 'organization';
GRANT ALL PRIVILEGES ON *.* TO 'organization'@'localhost' IDENTIFIED BY 'organization';
FLUSH PRIVILEGES;
CREATE DATABASE mariadb_sql_example_1;
EOF
echo "Fix SQL file"
sed -i "s/'0000-00-00'/NULL/g" ${SQL_PATH}
echo "Import SQL file"
mysql -u organization -porganization mariadb_sql_example_1 < ${SQL_PATH}
echo "Fix SQL in database"
./.venv/bin/python ./script/database/fix_mariadb_sql_example_1.py