Using MAMP and MySQL, logging in to MySQL command prompt after switching server ports.

I figured I’d write this down just so I have a record of it, and if it may be able to help other people. I ran into an interesting bug today.

For C# class at Epicodus, we use learn databasing using MAMP for persistent data storage. For those who don’t know what MAMP is, it’s basically a quick and easy way to set up a local database server for your coding projects to use.  There’s more to it than just that, but that’s the quickest easiest way I can explain it for now. I’m using MAMP on a PC with Windows 10, and I ran into an interesting issue.

Once you have MAMP installed (for help installing, check out this page), and you open it up, you’ll see this screen:

MAMP bootup

When the buttons next to Apache Server and MySQL server turn green, your server is up and running.

Due to class, we had to adjust the ports of the servers, so we do that by selecting the “Preferences” button, and navigating to the “Ports” tab in the preferences.

MAMP portPref

The ports were originally set to Apache: 80, Nginx (Apparently pronounced In-Jin-Ex): 80, and MySQL: 3306, but for class we had to change them to what you see in the image, 8888, 7888, and 8889 respectively.  After this you should be able to go into the MySQL from a terminal prompt, I use Windows Powershell. You’ll need to add the the MySQL environment variable to the System Path, do this, follow the steps below:

  1. Open the Control Panel and visit System > Advanced System Settings > Environment Variables…
  2. Then select PATH…, click Edit…, then Add.
  3. Add the exact location of your MySQL installation, as mentioned in step two above, and click OK. (This location is likely C:\MAMP\bin\mysql\bin, but may differ depending on your specific installation.)

Now at this point, you can go into Powershell and type

>"mysql -uroot -proot"

to login…. IN THEORY. But it didn’t work for me. I was googling for HOURS trying to figure this out until eventually I gave up because I learned that if I just switched the ports back to 80/80/3306, instead of 8888/7888/8889, I was able to log in to MySQL just fine. So something is goofy with the default ports.

The solution is to use the PORT flag which is represented by -P in the command line.

So the final string to log in with the ports changed to 8888/7888/8889 is:

> "mysql -uroot -proot -P 8889"

OR

> "mysql -uroot -proot --port=8889"

but without any of the quotes.

This will allow you to log into the MySQL command line interface if you’ve changed the ports.

No amount of googling had this answer anywhere, it was only thanks to my buddy Mikael that I was able to find this answer.

To troubleshoot it, we typed

> "mysql -help"

and it gave us a list of all possible commands, to which we found one named port and tried it out, and voila! It worked. **facepalm**

 

6 thoughts on “Using MAMP and MySQL, logging in to MySQL command prompt after switching server ports.

  1. Thanks this was really helpful but may I suggest leaving out the quotes.
    I understand you’d like to quote exactly what you typed but it can be confusing sometimes

    Like

Leave a comment