Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Database Foundations Securing and Maintaining a MySQL Database Setting up Multiple Users

Taylor Plante
Taylor Plante
22,283 Points

IP Address for new user remote access

I'm not sure what to fill in for an IP address when creating a new database for user1. I first tried using the IP address that Andrew uses in the video (which I figured wouldn't work) and that connection failed, so I next tried the IP address that automatically populates and that didn't work either. Any suggestions so I can follow along?

2 Answers

Marek Hrusovsky
Marek Hrusovsky
4,217 Points

First small recap: In the video they used 192.168.x.y to make connection to the database. IP or domain name can be used within the connection field. It should be provided by your hosting (look carefully or send them email). In case your database is in your computer than the ip is 127.0.0.1.

In the video they did not mention IP restriction option - restricting connections to the database. Example: My IP "188.167.232.186" CREATE USER 'marek'@'188.167.232.0/255.255.255.0';

This means that user marek is allowed to make connection to the database from any IP address that has 188.167.232 in it.

How do you find your IP address? http://www.whatismyip.com

PS: there is other option than 127.0.0.1. Try to open Terminal and hit this command "ifconfig | grep inet | grep -v inet6"

Mareks-MacBook-Pro:~ xhruso00$ ifconfig | grep inet | grep -v inet6 inet 127.0.0.1 netmask 0xff000000 inet 192.168.0.128 netmask 0xffffff00 broadcast 192.168.0.255 inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255 So if the database is on my computer I can make connection to the database on "192.168.0.128" or "192.168.0.122" or 127.0.0.1

So, I was unable to connect with user1 via localhost or its equivalent 127.0.0.1, and was able to fix the problem two different ways:

  1. Not changing Andrew's mysql statemant from the video at all, I was able to use my local IP address (ie 192.168.2.4) in Server Connection settings and use that to connect to the treehouse_moive_db.

To find you local IP address: On a Mac, go to System Preferences, click Network, and look for under "Ethernet" look for "IP Address" or under "Wi-Fi" and look for "Wi-Fi is connected to X and has the IP address of X.X.X.X". On a Windows PC, click the start button, click Run or click in the search box, type in cmd, hit Enter, type in "ipconfig", hit Enter, and look for IP Address or "IPv4 Address" for X.X.X.X (i.e. 10.1.42.2).

  1. Because I often change networks and my local IP address changes, I prefer this second way that lets you leave the IP address as 127.0.0.1 (which works even when I'm offline). To do this I follow the link that iainfriend mentioned: https://teamtreehouse.com/forum/cant-connect-user1-localhost-to-treehousemoviedb.

This has you modify Andrew's mysql statemant from the video changing user1@'%' to to user1@127.0.0.1. So, the whole mysql statemant looks like this:

GRANT SELECT ON treehouse_movie_db.* TO user1@127.0.0.1 IDENTIFIED BY 'password';

Even though I had already ran the GRANT SELECT statement, I ran the above statement again, and then ran the "FLUSH PRIVILEGES;" statement, and then I was able to connect using 127.0.0.1.