Skip to content

Commit d2d0316

Browse files
committed
Initial commit
0 parents  commit d2d0316

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# MAMP MySQL
2+
3+
### Overview
4+
Changing or re-setting the password for MAMP's MySQL root user necessitates updating hard-coded references to the old password in several Bash scripts shipped with MAMP for macOS.
5+
6+
As of MAMP 5.x these files are:
7+
* /Applications/MAMP/bin/checkMysql.sh
8+
* /Applications/MAMP/bin/quickCheckMysqlUpgrade.sh
9+
* /Applications/MAMP/bin/repairMysql.sh
10+
* /Applications/MAMP/bin/stopMysql.sh
11+
* /Applications/MAMP/bin/upgradeMysql.sh
12+
* /Applications/MAMP/bin/phpMyAdmin/config.inc.php
13+
14+
Instructions on changing the password for MAMP's MySQL root user and how to manually update each of these files can be found at [Changing the MySQL Root User Password in MAMP](https://www.tech-otaku.com/local-server/changing-mysql-root-user-password-mamp/).
15+
16+
### Purpose
17+
[mamp-mysql.sh](mamp-mysql.sh) is a Bash script that automates updating these files with the new password and is run from the command line.
18+
19+
### Instructions
20+
1. [Download](https://github.com/tech-otaku/mamp-mysql/archive/master.zip) mamp-mysql.sh
21+
1. Open the Terminal application in macOS.
22+
1. At the shell prompt
23+
1. type `chmod +x /path/to/mamp-mysql.sh` and press enter to make the script executable
24+
1. type `/path/to/mamp-mysql.sh OLDPASSWORD NEWPASSWORD` replacing `OLDPASSWORD` and `NEWPASSWORD` as appropriate and press enter to run the script
25+
26+
The script changes all occurrences of `OLDPASSWORD` with `NEWPASSWORD` in the designated files making a backup (.bak) of each file in its parent directory before any changes are made.
27+
28+
If either the `OLDPASSWORD` or the `NEWPASSWORD` are omitted, the script will exit with the error `ERROR: Usage is mamp-mysql.sh OLDPASSWORD NEWPASSWORD`.
29+
30+
If `OLDPASSWORD` is not found in an individual file the script will display the message `WARNING: Could not find old password 'OLDPASSWORD' in /Applications/MAMP/bin/filename.sh`.
31+
32+
If successful the script will display the message `Updated /Applications/MAMP/bin/filename.sh with new password 'NEWPASSWORD'` for each file updated.

mamp-mysql.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# Check if both the old [$1] and new [$2] MySQL root user passwords have been provided as command line arguements. Exit with error message if not.
4+
if [[ -z $1 || -z $2 ]]; then
5+
printf '\nERROR: Usage is mamp-mysql.sh OLDPASSWORD NEWPASSWORD\n'
6+
exit 1
7+
fi
8+
9+
# Define the parent directory containing the files to be updated.
10+
SOURCE=/Applications/MAMP/bin
11+
12+
# Define the names of the files to be updated excluding config.inc.php which is handled separately at the end of this script.
13+
declare -a files=("checkMysql.sh" "quickCheckMysqlUpgrade.sh" "repairMysql.sh" "stopMysql.sh" "upgradeMysql.sh")
14+
15+
printf '\n'
16+
# Iterate through the list of file names.
17+
for f in "${files[@]}"
18+
do
19+
# Check if file exists. Display warning message and skip to next file if not.
20+
if [ -f "$SOURCE/$f" ]; then
21+
# Check if the text `-uroot -pOLDPASSWORD` exists in the file. Display warning message if not.
22+
grep -e "-u[ ]*root -p[ ]*$1" "$SOURCE/$f" > /dev/null
23+
if [ $? -eq 0 ]; then
24+
# Change the old password in the file to the new password making a backup (.bak) first.
25+
sed -i '.bak' -E "s/(-u[ ]*root -p[ ]*)$1/\1$2/g" "$SOURCE/$f"
26+
# Display success message.
27+
echo "Updated $SOURCE/$f with new password '$2'"
28+
else
29+
# Display warning message regarding old password.
30+
echo "WARNING: Could not find old password '$1' in $SOURCE/$f"
31+
fi
32+
else
33+
# Display warning message regarding file doesn't exist.
34+
echo "WARNING: The file $SOURCE/$f does not exist"
35+
fi
36+
done
37+
38+
# Process the file config.inc.php checking first if it exists. Display warning message if not.
39+
if [ -f "$SOURCE/phpMyAdmin/config.inc.php" ]; then
40+
# Check if the text `'password'] ='OLDPASSWORD` exists in the file. Display warning message if not.
41+
grep -e "'password'\] *= '$1" "$SOURCE/phpMyAdmin/config.inc.php" > /dev/null
42+
if [ $? -eq 0 ]; then
43+
# Change the old password in the file to the new password making a backup (.bak) first.
44+
sed -i '.bak' -E "s/('password'\] *= ')$1/\1$2/g" "$SOURCE/phpMyAdmin/config.inc.php"
45+
# Display success message.
46+
echo "Updated $SOURCE/phpMyAdmin/config.inc.php with new password '$2'"
47+
else
48+
# Display warning message regarding old password.
49+
echo "WARNING: Could not find old password '$1' in $SOURCE/phpMyAdmin/config.inc.php"
50+
fi
51+
else
52+
# Display warning message regarding file doesn't exist.
53+
echo "WARNING: The file $SOURCE/phpMyAdmin/config.inc.php does not exist"
54+
fi
55+
printf '\n'

0 commit comments

Comments
 (0)