I am developing a personal web-site with a lot of relatively sensitive (genealogical) information stored in a MySQL database. The site engine is written in PHP. So far (prototype phase) I have only one MySQL account and have hard-coded the database login and password in PHP and implemented user authentication independently from MySQL authentication. So as long as people access my web-site via my PHP engine, it is secure. However if someone manages to get the PHP code itself, they will get full access to the database.

Is it possible and is it a good practice to additionally secure the database by creating a separate MySQL account for each site user and use user password to access MySQL? If yes, then would it be possible to somehow securely store the database login/password between sessions (to enable "remember me" functionality)?

I don't have much experience in web development, this is my first project involving a self-programmed CMS.

  • Your MySQL Server should not be accessible from the Internet. If it is, that is your first problem. Sep 12, 2015 at 20:28

1 Answer 1


No, it's not good practice to create a database user for every site user. The way you have things setup now is pretty standard. It shouldn't be possible for people to get access to passwords stored in your PHP code unless your server is compromised, and that's pretty much the worst case scenario.

The only caveat is that if you are using some form of source control for your project (e.g. Git), you shouldn't be keeping configuration files that contain passwords in the repository. That way you avoid accidentally exposing passwords if you're using a service like Github, or if you need to give other people access to your code.

  • I do not know PHP- I use another language- however, what is typically done prior to PHP was to create a library resource outside of the web space and do a require/include to include the library. In this library would be all of the database connection code and database authorization. Remember to keep it out of the web space so that it cannot be accessed from the outside. You would be doing a require/include and then a call to the library routine before accessing or writing data.
    – closetnoc
    Sep 12, 2015 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.