fix Access denied errors
parent
61114d55d1
commit
241e2d56e1
|
@ -325,24 +325,31 @@ if [[ "$PERFORM_DB_ROOT_RESET" == "true" ]]; then
|
||||||
info "$MYSQLD_SAFE_CMD started in background (PID: $MYSQLD_SAFE_PID). Waiting for it to initialize..."
|
info "$MYSQLD_SAFE_CMD started in background (PID: $MYSQLD_SAFE_PID). Waiting for it to initialize..."
|
||||||
sleep 10 # Allow generous time for safe mode startup
|
sleep 10 # Allow generous time for safe mode startup
|
||||||
|
|
||||||
|
# Generate a simpler password without special characters to avoid auth issues
|
||||||
|
new_root_password=$(openssl rand -base64 12 | tr -dc 'a-zA-Z0-9' | head -c 16)
|
||||||
|
info "Using simplified password format: $new_root_password"
|
||||||
|
|
||||||
info "Attempting to reset root password using mysql client..."
|
info "Attempting to reset root password using mysql client..."
|
||||||
# Use sudo for mysql command connecting via socket as root
|
# Use sudo for mysql command connecting via socket as root
|
||||||
if ! sudo mysql --protocol=socket -u root <<-EOF &> /dev/null
|
if ! sudo mysql --protocol=socket -u root <<-EOF &> /dev/null
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
ALTER USER 'root'@'localhost' IDENTIFIED BY '$new_root_password';
|
ALTER USER 'root'@'localhost' IDENTIFIED BY '$new_root_password';
|
||||||
FLUSH PRIVILEGES;
|
|
||||||
EXIT
|
|
||||||
EOF
|
|
||||||
then
|
|
||||||
warning "Failed 'ALTER USER' reset attempt (may be normal). Trying root@127.0.0.1..."
|
|
||||||
if ! sudo mysql --protocol=socket -u root <<-EOF &> /dev/null
|
|
||||||
FLUSH PRIVILEGES;
|
|
||||||
ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '$new_root_password';
|
ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '$new_root_password';
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
EXIT
|
EXIT
|
||||||
EOF
|
EOF
|
||||||
then
|
then
|
||||||
warning "Failed 'ALTER USER root@127.0.0.1' reset attempt. Trying legacy 'UPDATE' method..."
|
warning "Failed 'ALTER USER' reset attempt (may be normal). Trying alternative syntax..."
|
||||||
|
# Try the mysql_native_password plugin explicitly
|
||||||
|
if ! sudo mysql --protocol=socket -u root <<-EOF &> /dev/null
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$new_root_password';
|
||||||
|
ALTER USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '$new_root_password';
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
EXIT
|
||||||
|
EOF
|
||||||
|
then
|
||||||
|
warning "Failed with native password plugin. Trying legacy 'UPDATE' method..."
|
||||||
# Fallback for older MySQL/MariaDB versions
|
# Fallback for older MySQL/MariaDB versions
|
||||||
if ! sudo mysql --protocol=socket -u root <<-EOF &> /dev/null
|
if ! sudo mysql --protocol=socket -u root <<-EOF &> /dev/null
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
|
@ -402,11 +409,25 @@ info "Creating WordPress database '$DB_NAME' and user '$DB_USER'..."
|
||||||
SQL_COMMAND=$(printf "CREATE DATABASE IF NOT EXISTS \`%s\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER IF NOT EXISTS '%s'@'%s' IDENTIFIED BY '%s'; GRANT ALL PRIVILEGES ON \`%s\`.* TO '%s'@'%s'; FLUSH PRIVILEGES;" \
|
SQL_COMMAND=$(printf "CREATE DATABASE IF NOT EXISTS \`%s\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER IF NOT EXISTS '%s'@'%s' IDENTIFIED BY '%s'; GRANT ALL PRIVILEGES ON \`%s\`.* TO '%s'@'%s'; FLUSH PRIVILEGES;" \
|
||||||
"$DB_NAME" "$DB_USER" "$DB_HOST" "$DB_PASSWORD" "$DB_NAME" "$DB_USER" "$DB_HOST")
|
"$DB_NAME" "$DB_USER" "$DB_HOST" "$DB_PASSWORD" "$DB_NAME" "$DB_USER" "$DB_HOST")
|
||||||
|
|
||||||
# Use the DB_ROOT_PASS (either provided or newly generated)
|
# Try connecting to localhost via socket first if TCP connection fails
|
||||||
if ! mysql -u "$DB_ROOT_USER" -p"$DB_ROOT_PASS" -h "$DB_HOST" -e "$SQL_COMMAND"; then
|
if ! mysql -u "$DB_ROOT_USER" -p"$DB_ROOT_PASS" -h "$DB_HOST" -e "$SQL_COMMAND"; then
|
||||||
|
warning "Failed to connect via TCP ($DB_HOST). Trying socket connection to localhost..."
|
||||||
|
if ! mysql -u "$DB_ROOT_USER" -p"$DB_ROOT_PASS" --protocol=socket -e "$SQL_COMMAND"; then
|
||||||
|
# If socket fails too, try with no password (in case reset made blank password)
|
||||||
|
warning "Socket connection failed too. Trying without password..."
|
||||||
|
if ! mysql -u "$DB_ROOT_USER" --protocol=socket -e "$SQL_COMMAND"; then
|
||||||
error_exit "Failed to execute SQL command to create WordPress database/user. Check MySQL/MariaDB logs and permissions for '$DB_ROOT_USER'."
|
error_exit "Failed to execute SQL command to create WordPress database/user. Check MySQL/MariaDB logs and permissions for '$DB_ROOT_USER'."
|
||||||
|
else
|
||||||
|
warning "Connected without password! MySQL root has no password now."
|
||||||
|
# Update the root password again to be sure
|
||||||
|
SECURE_ROOT_SQL="ALTER USER 'root'@'localhost' IDENTIFIED BY '$DB_ROOT_PASS'; FLUSH PRIVILEGES;"
|
||||||
|
mysql -u "$DB_ROOT_USER" --protocol=socket -e "$SECURE_ROOT_SQL" || warning "Could not secure root user with password!"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
success "Database '$DB_NAME' and user '$DB_USER' created successfully via socket connection."
|
||||||
|
else
|
||||||
success "Database '$DB_NAME' and user '$DB_USER' created successfully."
|
success "Database '$DB_NAME' and user '$DB_USER' created successfully."
|
||||||
|
fi
|
||||||
|
|
||||||
# --- WordPress Core File Setup ---
|
# --- WordPress Core File Setup ---
|
||||||
info "Ensuring WordPress files are present in: $WP_ROOT"
|
info "Ensuring WordPress files are present in: $WP_ROOT"
|
||||||
|
|
Loading…
Reference in New Issue