Created
August 1, 2021 07:16
-
-
Save holly/5355af3ea447283aac899950ae589e9d to your computer and use it in GitHub Desktop.
oneliner mysql_secure_install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [ $# != 1 ]; then | |
echo "Usage: mysql_secure_install.sh \$password" | |
exit 1 | |
fi | |
MYSQL_CMD="/usr/bin/mysql -B" | |
ROOT_PASSWORD=$1 | |
res=$($MYSQL_CMD -e "SELECT component_urn FROM mysql.component WHERE component_urn = 'file://component_validate_password'") | |
if [ -z "$res" ] ; then | |
$MYSQL_CMD -e "INSTALL COMPONENT 'file://component_validate_password'" | |
fi | |
cat <<EOF | $MYSQL_CMD | |
SET GLOBAL validate_password.policy = 'LOW'; | |
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$ROOT_PASSWORD'; | |
DELETE FROM mysql.user WHERE User=''; | |
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); | |
DROP DATABASE IF EXISTS test; | |
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; | |
FLUSH PRIVILEGES; | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment