Results 1 to 4 of 4

Thread: [RESOLVED] mysql database user

  1. #1

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Resolved [RESOLVED] mysql database user

    It might be a stupid question, but is a question nonetheless. On my desktop with wampserver on, I have been connecting to all the databases with a common username and password.
    PHP Code:
    mysql_connect("localhost","root","password"
    When I create database on the server hosting my site, I realize that I can't have same username for two databases. In my php files, I had used the above code to establish connection to whichever database I required. Now, I will have to alter the code specifically for each of the databases.
    Is there an alternative to this? Can I use localhost and root on my server?
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: mysql database user

    Create a user and give them access to the databases.

    Users should never be using root access to access your databases. Limiting them to the basics of what they need is best.

    If you have phpMyAdmin, it has a fairly simple interface to achieve this.

  3. #3
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: mysql database user

    You can usually still use "localhost" for the connection, unless your host specifies something else. And you know that mysql_connect() isn't what selects your database, right? mysql_select_db() does that. I believe you can, in fact, have the same login work for multiple databases if it has permissions to both.

    As kfcSmitty said, you should never have your scripts connecting as "root," the problem being that it has full access to your database: it can read from, write to, truncate, or drop any table in the database. You want to limit access to curtail the malicious things that can be done.
    Last edited by SambaNeko; Jul 16th, 2009 at 03:25 PM.

  4. #4

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Resolved Re: mysql database user

    Thanks to both of you.
    I might not get rights on localhost on the server, so I decided to have separate users of databases even though I had to type few more lines of codes.
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width