I've just installed and set up Apache, MySQL, PHP and phpMyAdmin on my small Mac laptop to be able to possess a local development atmosphere. But once i moved among my projects to the neighborhood server I recieve a strange MySQL error in one of my calls to mysql_query():

Access refused for user '_securityagent'@'localhost' (using password: NO)

To begin with, the query I am delivering to MySQL is valid, and I have even testet it through phpMyAdmin with perfect result. Next, the mistake message only happens here as i have a minimum of 4 other mysql connections and queries per page. This call to mysql_query() happens in the finish of the really lengthy function that handles data for recently produced or modified articles. This essentially what it really does:

  1. Collect all of the data from article form (title, content, dates, etc..)
  2. Validate collected data
  3. Connect with database
  4. Dynamically build SQL query according to validated article data
  5. Send query to database before closing the bond

Pretty fundamental, I understand. I didn't recognize the username "_securityagent" so following a quick search I discovered this from articles at Apple's Developer Connection speaking about some random bug:

Mac OS X's security infrastructure will get for this problem by running its GUI code like a special user, "_securityagent".

In order recommended by Frank within the comments I put a var_dump() on all variables utilized in the mysql_connect() call, and each time that it returns the right values (where username isn't "_securityagent" obviously). Thus I am wondering if anybody has any idea why 'securityagent' is attempting for connecting to my database - and just how I'm able to bare this error from occurring after i call mysql_query().

If username isn't specified clearly, MySQL attempts to guess it by utilizing title of current system user.

It's not necessary to believe that, you need to simply specify preferred username clearly.

How – that is dependent how you are hooking up. Just in case of phpMyAdmin it's config.inc.php, add line like:

$cfg['Servers'][0]['user'] = 'Eirik';

(see manual)

Have you setup the local Amplifier server utilizing a pre-made package, or have you install MySQL, PHP, etc. with the particular OS-specific download packages? Establishing Apache, MySQL, and PHP4/5 could be a real PITA.

If you are getting issues with your setup I'd recommend MAMP. It is a great all-in-one package that actually does the secret. You are able to still access all of the config files you would like, and things are included in the MAMP folder rather than spread all around the system. If Apple upgrades the pre-installed version of Apache/PHP, your machine-specific config would not be overridden because it would within the situation of utilizing pre-installed Apache/PHP.