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

Ralph Johnson
Ralph Johnson
10,408 Points

Can you pass a variable to "IDENTIFIED BY?"

As an admin, you'd be able to access the database directly. No problem. So you can directly assign a literal string to IDENTIFIED BY.

But suppose you want to accept inputted information (stored in a database or table) from a user? I'm thinking along the lines of a signup page, or something like that. Normally you'd have a user create his/her own password, and you wouldn't want any Tom, Dick or Harry to have access to a user's personal information. You need to grant write access on some level, or the user wouldn't be able to create or edit profile info. So wouldn't the IDENTIFIED BY password have to be passed from some sort of script variable, from user input?

Or is there a different way that is normally handled?

4 Answers

I think you're confused. We're talking about database users here, not users stored in the database. Generally, you use a certain username/password combination for a certain application to access certain databases (e.g. a certain website.). For example:

You have a website, teamtreehouse.com. It uses a database called 'teamtreehouse', the database can be accessed using the username 'teamtreehouse' and the password 'password'. You have another website, google.com. It uses a database called 'google', the database can be accessed using the username 'google' and the password 'password'. And so on...

To answer your question, yes you can use variables. The database users and passwords are actually stored in the database as well. But I don't think that's what you want, unless you want to have a system where users can directly access and/or modify the database.

See: https://dev.mysql.com/doc/refman/5.6/en/assigning-passwords.html if you want to know how and where exactly passwords are stored.

Hi Ralph! I understand your frustration and henkvanveen makes a very valid point, practice is key. If you haven't worked with databases before, there are a lot of books and tutorials (there are some RoR tutorials on the web that go from dev to deploy) that can give you more information and reference that you can use with these videos (for database design, Database Design for Mere Mortals is a great reference book and I reference it in my day job and it is RDMS independent). I sometimes have to look at books or the actually documentation for the feature or code, e.g. the Rails website: http://rubyonrails.org/documentation/ which lists a plethora of reference materials and books.

Keep at it and track/ identify those functions or code you don't understand to return to it later. Sometimes you won't understand it the first time, but when you do, it will be worth it! Happy coding!

Ralph Johnson
Ralph Johnson
10,408 Points

Henkvanveen, thanks for your answer. I think I AM confused, very much so. I'm approaching the end of the "ruby development track," and it's apparent that I'm not going to be able to deploy a simple rails-based website with minimal, low-octane database integration when I'm done.

I have yet to find a tutorial that didn't either: completely change its paradigm mid-stream (making backtracking to an earlier page impossible because the page no longer exists in its previous form) [railstutorial.org], OR leave out important steps necessary to understanding the rails folder/file structure and relationships between controllers, models, and views. I can figure out how to function in a programming language--it may take some searching and trial and error, but I haven't had too much problem with that. What I DON'T know is the nuts and bolts of how this all fits together to make an actual dynamic web page, and everybody seems to just gloss over that part or put it off 'til "later." I'm two units from the end, and the last part covers user authentication (which is, as you pointed out, probably the part I'm confused about). Then...it's OVER. After building the rails "Todo" app two or three units ago, I have no idea what it takes to deploy that thing (or any app I might come up with). I'm thinking "later" isn't coming. It's approximately a 60-hour track (I'm 10 hours from the end) and when I get done I'll be able to do...nothing.

I've taken two courses in Javascript, and have yet to learn how to interface it with an HTML page.

I took a PHP course (most of which I've now forgotten, from lack of application). Same deal, a lot of rehash of basic programming concepts, with little or no actual implementation.

I don't know how to make the pieces connect, and nobody seems to want to bother explaining that. All I want to do, at the moment, is create a simple interactive site that stores information in a database--one that allows users/contractors to access schedules, accept assignments, check off tasks, and find out how and when they're going to get paid. It shouldn't require an MIT degree to do that, but I'm spending hours and hours, and the most common phrase I hear is "don't worry about that now." When do we worry about "it?"

If I can't learn how to put the pieces together, then all I have is a pile of building blocks--which I might as well put back in the toybox to avoid leaving a mess on the floor for mommy and daddy to trip over.

I like Andrew, the brit database guy. Very friendly, and explains things fairly well (until this last part, which confused me). I'm on to the next unit, ActiveRecord, and that teacher sounds like he smoked too much weed before turning the camera on--I've never seen such a disorganized, frazzled presentation. He says he's using MySQL, then finds out (to his surprise!!) that he DIDN'T, doesn't bother to explain how to make that happen, says "oh--huh...we're using SQLite3...oh well, we'll just go on then..."

I'm getting pretty irritated. When do we learn how to DO something?

I feel like I'm writing a Dear Abby letter. :)

Signed, Vexed in Vegas

I understand it can be overwhelming. The key is practice. Did you watch all of the tutorials from the Database Foundations course? If you haven't worked with databases before, you should really watch them all to understand how databases work. I'm pretty sure you'll be able to answer at least this question when you're done with that. You'll know that you'll have to create a database for your application and a table within that database to hold the user information. In other words, you'll have to model it yourself. If you already understand this part, I can get down to the details. Hope this helps.