Solved

Access denied for user: '@localhost' to database 'myblog'

Posted on 2004-10-06
9
795 Views
Last Modified: 2013-12-12
I am having a problem trying to connect with MySQL with PHP.  I get this error.  Access denied for user: '@localhost' to database 'myblog'

This is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
      <title>Untitled</title>
</head>

<body>
<?
      ini_set ('display_errors', 1);
      error_reporting (E_ALL & ~E_NOTICE);
      
      if ($dbc = mysql_connect('127.0.0.1', 'fizz', '************')) {          // I covered my password
            print '<P>Successfuly connected to MySQL.</P>';
            mysql_close();
      } else {
            print '<p>Could not connect to MySQL.</p>';
      }
      
      if (@mysql_query ('CREATE DATABASE myblog')) {
            print '<P>The Database has been created!</P>';
      } else {
            die ('<p>Could not create the database because: <b>' . mysql_error() . '</b></p>');
      }
?>

</body>
</html>

END CODE

And as you can see in this screen shot: http://fizzmahon.2mydns.com/error.jpg
i have all the privaledges....

after running my code in a browser i get this...
-------
Successfuly connected to MySQL.

Could not create the database because: Access denied for user: '@localhost' to database 'myblog'
-------

and you can see it for yourself here: http://fizzmahon.2mydns.com/Temp/mysql.php

THANKS IN ADVANCED!!!  IF YOU NEED ANY MORE INFO I CAN TELL YOU =D

FiZZ


0
Comment
Question by:DIDD0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 12242776
Possibly you have to use mysql_connect('localhost',......), but that's just a hunch. Or change the localhost-domain in your user management into 127.0.0.1

Regards

-r-
0
 

Author Comment

by:DIDD0
ID: 12242784
nope same error
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12242839
<?
     ini_set ('display_errors', 1);
     error_reporting (E_ALL & ~E_NOTICE);
     
     if ($dbc = mysql_connect('127.0.0.1', 'fizz', '************')) {          // I covered my password
          print '<P>Successfuly connected to MySQL.</P>';
          mysql_close();
     } else {
          print '<p>Could not connect to MySQL.</p>';
     }

mysql_query ("CREATE DATABASE myblog") or die (mysql_error());

?>

Can you post the error if you use this code... thanks
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

Author Comment

by:DIDD0
ID: 12242961
Successfuly connected to MySQL.

Access denied for user: '@localhost' to database 'myblog'
0
 
LVL 12

Accepted Solution

by:
minichicken earned 75 total points
ID: 12243341
Is it working now? I just check your link http://fizzmahon.2mydns.com/Temp/mysql.php

and got this as the result, the DB has been created....

*************************************
Successfuly connected to MySQL.

Could not create the database because: Can't create database 'myblog'. Database exists
0
 

Author Comment

by:DIDD0
ID: 12243400
thats wierd...  let me check
0
 

Author Comment

by:DIDD0
ID: 12243410
Yes it is working now...  but i didnt change anything?!?!?! all i did was install phpmyadmin...

anyways i will grant you points...
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12243444
thanks DIDD0 :) greatly appreciated ^_^
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12243459
Well, good that it working for you :)

However, I did try the code I posted above locally and it worked.....
but on my MySQL, I use "root" as the user with a blank password.
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question