By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Error 1044 Access denied to database

P: n/a
Hello.

I am currently working through a book on Dreamweaver and using PHP. I
am having a little trouble with setting up the database though. I
have php 4.2.3 and MySQL 4.0.20a. I am running locally with Apache
1.3.27 on Windows XP Pro.

I seem to have finally got MySQL running after a lot of difficulty.
In the book it says to type source C:\mysql\newland_tours.sql at the
mysql> prompt, to generate the newland_tours database in my copy of
MySQL.

When I do this however it gives me an error message saying:

Error 1044 Access denied for user: '@localhost' to database
'newland_tours'

and numerous other ones saying:

Error 1046 No Database Selected

If you can help me I'd be very grateful. I think that something must
be wrong or amiss with the settings or the paths to the files in
my.ini file? Or perhaps it is just a bug with php or MySql?

Thanks very much for any help

John
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
John wrote:
I seem to have finally got MySQL running after a lot of difficulty.
In the book it says to type source C:\mysql\newland_tours.sql at the
mysql> prompt, to generate the newland_tours database in my copy of
MySQL.

When I do this however it gives me an error message saying:

Error 1044 Access denied for user: '@localhost' to database
'newland_tours'


Make sure that the correct user is defined in mysql and supply it, e.g.:

path\to\mysql-installation\bin\mysql -uroot -prootpasswd < newland_tours.sql

For more info on priveleges, see:

http://dev.mysql.com/doc/mysql/en/De...rivileges.html and
http://dev.mysql.com/doc/mysql/en/GRANT.html
JW

Jul 17 '05 #2

P: n/a
On Sat, 05 Jun 2004 20:59:00 GMT, "Janwillem Borleffs"
<jw@jwscripts.com> wrote:
John wrote:
I seem to have finally got MySQL running after a lot of difficulty.
In the book it says to type source C:\mysql\newland_tours.sql at the
mysql> prompt, to generate the newland_tours database in my copy of
MySQL.

When I do this however it gives me an error message saying:

Error 1044 Access denied for user: '@localhost' to database
'newland_tours'

Make sure that the correct user is defined in mysql and supply it, e.g.:

path\to\mysql-installation\bin\mysql -uroot -prootpasswd < newland_tours.sql


How exactly do I define correct user and supply it?

When I go to the mysql> prompt do I type in what you have put?

path\to\mysql-installation\bin\mysql -uroot -prootpasswd <
newland_tours.sql

I understand everything here: path\to\mysql-installation\bin\mysql

but I don't have a clue about this: -uroot -prootpasswd <
For more info on priveleges, see:

http://dev.mysql.com/doc/mysql/en/De...rivileges.html and
http://dev.mysql.com/doc/mysql/en/GRANT.html


I have taken a look at these links and all the different sections and
subsections, but it is far too complex for me. I am just a beginner.
I need it explained simply what to do.

Cheers

John
Jul 17 '05 #3

P: n/a

"John" <ph********@needshelp.com> wrote in message
news:gb********************************@4ax.com...
On Sat, 05 Jun 2004 20:59:00 GMT, "Janwillem Borleffs"
<jw@jwscripts.com> wrote:
John wrote:
I seem to have finally got MySQL running after a lot of difficulty.
In the book it says to type source C:\mysql\newland_tours.sql at the
mysql> prompt, to generate the newland_tours database in my copy of
MySQL.

When I do this however it gives me an error message saying:

Error 1044 Access denied for user: '@localhost' to database
'newland_tours'

Make sure that the correct user is defined in mysql and supply it, e.g.:

path\to\mysql-installation\bin\mysql -uroot -prootpasswd <

newland_tours.sql
How exactly do I define correct user and supply it?

When I go to the mysql> prompt do I type in what you have put?

path\to\mysql-installation\bin\mysql -uroot -prootpasswd <
newland_tours.sql

I understand everything here: path\to\mysql-installation\bin\mysql

but I don't have a clue about this: -uroot -prootpasswd <
For more info on priveleges, see:

http://dev.mysql.com/doc/mysql/en/De...rivileges.html and
http://dev.mysql.com/doc/mysql/en/GRANT.html


I have taken a look at these links and all the different sections and
subsections, but it is far too complex for me. I am just a beginner.
I need it explained simply what to do.

Cheers

John


What Janwillem Borleffs meant was this: Suppose your username for mysql is
"John" and your password is "bafooey", when you're starting up MySQL in the
prompt, type this:

path\to\mysql-installation\bin\mysql -uJohn -pbafooey

However you may not have created any usernames/passwords for MySQL yet... if
this is the case, type this at the prompt instead:

path\to\mysql-installation\bin\mysql -uroot -p

This will log you in as the root user (the root user is the user with access
to all databases and all tables within the databases). Once mysql is open
then type this:

\u mysql

^that selects the MySQL database where you can create users. to create a
user type this:

GRANT ALL ON newland_tours.* TO John@localhost IDENTIFIED BY "bafooey";

^^ that command creates the user John with password "bafooey". the
"newland_tours.*" means that the user John has access to all tables in the
newland_tours database (the * means all tables). Once you have created this
user, you can use it to work on the newland_tours database and not have
access problems.

hope this helped

- JP
Jul 17 '05 #4

P: n/a
What Janwillem Borleffs meant was this: Suppose your username for mysql is
"John" and your password is "bafooey", when you're starting up MySQL in the
prompt, type this:
I think that MySql already starts up automatically when my system is
switched on as I have a traffic lights icon in the system tray which
is on green?
path\to\mysql-installation\bin\mysql -uJohn -pbafooey
When I type this with the username and password that were created in
the my.ini file it gives the following:

Outfield Disabled.
ERROR:
Unknown command '\m'.
ERROR:
Unknown command '\b'.
ERROR:
Unknown command '\m'.

However you may not have created any usernames/passwords for MySQL yet... if
this is the case, type this at the prompt instead:

path\to\mysql-installation\bin\mysql -uroot -p


If I try this without username and password it gives the same error as
before.

MySql is so frustrating to set up it's unbelievable.

John
Jul 17 '05 #5

P: n/a
In article <gb********************************@4ax.com>,
John <ph********@needshelp.com> wrote:
On Sat, 05 Jun 2004 20:59:00 GMT, "Janwillem Borleffs"
<jw@jwscripts.com> wrote:
John wrote:
I seem to have finally got MySQL running after a lot of difficulty.
In the book it says to type source C:\mysql\newland_tours.sql at the
mysql> prompt, to generate the newland_tours database in my copy of
MySQL.

When I do this however it gives me an error message saying:

Error 1044 Access denied for user: '@localhost' to database
'newland_tours'


Make sure that the correct user is defined in mysql and supply it, e.g.:

path\to\mysql-installation\bin\mysql -uroot -prootpasswd < newland_tours.sql


How exactly do I define correct user and supply it?

When I go to the mysql> prompt do I type in what you have put?

path\to\mysql-installation\bin\mysql -uroot -prootpasswd <
newland_tours.sql

I understand everything here: path\to\mysql-installation\bin\mysql

but I don't have a clue about this: -uroot -prootpasswd <
For more info on priveleges, see:

http://dev.mysql.com/doc/mysql/en/De...rivileges.html and
http://dev.mysql.com/doc/mysql/en/GRANT.html


I have taken a look at these links and all the different sections and
subsections, but it is far too complex for me. I am just a beginner.
I need it explained simply what to do.

Cheers

John


Buy a book on MySQL and read it. It's whole other rathole in addition
to php. You'll need to understand what a real DBMS is doing and how it
does it. It's not trivial. Be ready for your brain to turn to tapioca
and leak out your ears.

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #6

P: n/a
On Sat, 05 Jun 2004 22:59:01 -0700, "Michael Vilain
<vi****@spamcop.net>" wrote:
Buy a book on MySQL and read it. It's whole other rathole in addition
to php. You'll need to understand what a real DBMS is doing and how it
does it. It's not trivial. Be ready for your brain to turn to tapioca
and leak out your ears.


I already have two books.

John
Jul 17 '05 #7

P: n/a
John wrote:
If you can help me I'd be very grateful. I think that something must
be wrong or amiss with the settings or the paths to the files in
my.ini file? Or perhaps it is just a bug with php or MySql?


It is not a bug, and it has nothing to do with php, so alt.php,
alt.comp.lang.php and comp.lang.php groups are not concerned about this
problem.

And even if this would be problem for php also, don't post to several
different newsgroups. Pick one group and one group only and post your
question to there. If you fail to get help from there, think again was
the group selection good or bad and did you ask the question properly.
If you think yes, then you can try another group. Why you should do
this? Because many people don't usually even bother to answer people who
post the question into many newsgroups, because it is against the
netiquette. This is only a friendly advice, because you might not know
this "rule". Don't be offended by me reminding it.

Now, to your problem.

When you installed MySQL you had a root account at the very beginning.
You might have changed the password for it, but if you havent, the
password is empty. The root user has privileges to do anything in the
database, while test user (which is the user you seem to have logged in,
has privileges only in the "test" database.) Try to start your mysql
console program like this:

mysql -u root

If you can get in, you don't have a root password, but that doesn't
matter with this problem. When you get in, try to type the command you
tried earlier:

source C:\mysql\newland_tours.sql

It should not give the same error anymore.

Follow-ups set to mailing.database.mysql only
Jul 17 '05 #8

P: n/a
On Sat, 05 Jun 2004 21:20:45 +0100, John <ph********@needshelp.com>
wrote:

I seem to have finally got MySQL running after a lot of difficulty.
In the book it says to type source C:\mysql\newland_tours.sql at the
mysql> prompt, to generate the newland_tours database in my copy of
MySQL.


I remember how confusing rhis can be. Before you start loading
databases, you need to know exactly how to log in at the mysql command
line. It gets confusing right there because you log in a bit
differently depending on whether or not you set up a user & password.

First off, you need to see if you can log in correctly. So, open your
Command Prompt and cd to the mysql/bin directory. On my machine, it's:

C:\> cd c:\mysql\bin

Once you get to the correct directory, try logging in without any
username or password like this:

C:\mysql\bin\> mysql

That will log you in as the root user if you haven't already set up a
password for root. If you have set a password up, then you can log in
with it like this:

C:\mysql\bin> mysql -u root -p

And then mysql will prompt you for the root password. The -u stands
for "user", which in this case is root. To log in as egghead, type:

C:\mysql\bin> mysql -u egghead -p

The -p means: prompt me for a password.

Now you can get your database loaded up. It will be easier for you if
you copy the C:\mysql\newland_tours.sql file to the mysql\bin
directory. Once you've done that, cd to the mysql\bin directory as if
you were going to log in, and do this:

C:\mysql\bin\mysql < newland_tours.sql

Or if you have a password,

C:\mysql\bin\mysql -u root -p < newland_tours.sql

And enter the password when prompted. If all goes well, you'll get
dumped back to the original prompt with no messages.

If you get errors, and you probably will:

Check that the database already exists. If not, then log in and create
it.

If it says "No database selected", open up the newland_tours.sql
file in notepad, and on the top line type:

USE DATABASE newland_tours;

or whatever the database name is. That should do it!

Jul 17 '05 #9

P: n/a
Sounds like theres not telling it what user to use - if you haven't set
on up you should be able to use the root user (root@localhost) - as an
aside why not just use easyPHP to set up mysql/apache - it take five
minutes??)
Jul 17 '05 #10

P: n/a
Hey there.
I just started subscribing to some php news-lists, and this was the one
looking the closest to what I was hoping to find when venturing out on my
local news-server.

As I am fairly new in the world of PHP scripting, I would like to know if
any of you would be so kind to give me some suggestions on my current
project.
It's called Squid-Switcher (a stripped down version of it is available and
is called VHost-List).

One of my current topics of self-discussion is security, features to come
and... right... this array problem I have been unable to figure out how to
solve.

All my code is released under the GNU GPL license, so do with it what you
will, as long as you're sharing it to the rest of the world :)

Here is the code to Squid-Switcher 0.2.4 who's main purpose is to present a
web front end for users, allowing them to change the outgoing IP on a Squid
proxy server without having to edit any files, figure out what IP's are
available at the machine and resolving them to see which ones are up or
down.
Any improvements to my half-descent code is welcomed, as long as you share
it with the rest of us!

A working demo could be seen at http://sokaris.yi.se/squid-switcher/ , but
that host has gone down... but thats another story.... for more of my little
projects, check out http://sobek.yi.se/projects/web_code/

For more info about me, check out http://erik.yi.se.

This code is my way of saying hello! :)

// Erik Söderström

<?php echo "<?xml version=\"0\" encoding=\"ISO-8859-1\"?>";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns = "http://www.w3.org/1999/xhtml" >
<head ><link rev="made" href="http://www.yi.se" />
<title>Squid - Switcher[by: Erik Söderström]</title >
<?php echo "<!--\n\n\n\n\n\n\n\n\n\n\n\n\t\t|\n\t\t|\n\t\t| Squid-Switcher
0.2.4\n\t\t|\n\t\t| (c)".date("Y")." Erik T. Söderström\n\t\t|\n\t\t|
http://erik.yi.se\n\t\t|\n\t\t|\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\
n\n-->";?>
<style type = "text/css" ><!--
body {
margin-left: 10px;
margin-right: 0px;
margin-width:0px;
margin-height:0px;
margin-top: 5px;
margin-bottom: 0px;
background: #e1e1e1;
}

font {
font-family:verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
cursor: default;
color: #000000;
font-weight: smaller;
}

font.green {
font-family:verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
cursor: default;
color: green;
font-weight: smaller;
}

font.red {
font-family: verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
cursor: default;
color: red;
font-weight: smaller;
}

font.bold {
font-weight: bold;
font-size: 11px;
font-family: Verdana, Geneva, Arial;
color: #000000;
text-decoration: none;
cursor: default;
}

a:link {
color: #000000;
}

a:visited {
color: #000000;
}

a:active {
color: #ffffff;
}

a:hover {
color: #0000ff;
}
-->
</style ></head ><body>
<?php
// --- GPL LICENSE APPLIES TO ALL CODE BELOW --- //
// --- http://www.gnu.org/licenses/gpl.txt --- //

// --- CONFIG: General --- //
set_time_limit("600");
$output = "";
$remoteuser = $_SERVER["REMOTE_ADDR"];
$use = $_GET['use'];
$action = $_GET['action'];
$path = realpath('.');

// --- CONFIG: Output related --- //
$vhosts_file = "vhosts.txt";
$vhosts_file_tmp = "vhosts.txt.tmp";
$colors = array('#ffffff', '#e1e1e1');
$chrlimit = "false";
$chrlength = 80;

// --- CONFIG: IP-related --- //
$ipserie = "205.217.166.";
$startip = 1;
$endip = 254;
$findpattern = '/^205\.217\.166\.(\d{1,3})$/';

// --- CONFIG: Logging --- //
$log_file = "squid-switcher_log.txt";
$logging = "true";
$time = date("d/M/Y:H:i:s");
// --- CONFIG: Squid-related --- //
$squidconf = "/etc/squid.conf";
$squidpid = "/var/run/squid.pid";

// --- THE SCRIPT --- //
function
modconf($ptrn, $newip, $sqconf, $sqpid)
{
if (!preg_match($ptrn, $newip, $matches)) {
die('You entered a non valid IP.');
} else {
if ($matches[1] < 1 || $matches[1] > 255)
die('You entered a non valid IP.');
$replace = 'tcp_outgoing_address ' . $newip;
$sContent = implode('', file($sqconf));
$ptrn = '/tcp_outgoing_address 205\.217\.166\.(\d{1,3})/';
$contents = preg_replace($ptrn, $replace, $sContent);
if ($fd = @fopen($sqconf, "w")) {
if (!@fwrite($fd, $contents)) {
echo "Error writing to file";
}
fclose($fd);
} else {
die("Could not open $filename for reading and writing");
}
}
$spid = file_get_contents($sqpid);
exec("kill -HUP ".$spid);
}
function
file_get_contents($filename)
{
$fd = fopen("$filename", "rb");
$content = fread($fd, filesize($filename));
fclose($fd);
return $content;
}
function
writefile($filename, $data, $mode)
{
$fp = fopen($filename, $mode);
fwrite($fp, $data);
fclose($fp);
}
//$ptrn = '/tcp_outgoing_address 205\.217\.166\.(\d{1,3})/';
$ptrn = preg_replace('/(\^|\$|\/)/', '', $findpattern);
preg_match_all('/('.$ptrn.')/', file_get_contents($squidconf),
$ipad[][$current]);

echo "<font class=\"bold\">&raquo;&nbsp;Squid-Switcher
0.2.4</font>&nbsp;<font>(<a href=\"?action=update\"
onmouseover=\"window.status='Update the list of virtual hosts.';return
true\" onmouseout=\"window.status='';return true\" target=\"_self\">update
list</a>)&nbsp;(<a href=\"?action=readlog\"
onmouseover=\"window.status='Read the logfile contents.';return true\"
onmouseout=\"window.status='';return true\" target=\"_self\">read
log</a>)&nbsp;(<a href=\"?action=viewsource\"
onmouseover=\"window.status='View the sourcecode of
".basename($_SERVER["PHP_SELF"])."';return true\"
onmouseout=\"window.status='';return true\" target=\"_self\">view
source</a>)&nbsp;(<a href=\"javascript:history.go(-1)\"
onmouseover=\"window.status='Go to the previous page.';return true\"
onmouseout=\"window.status='';return true\" target=\"_self\">go
back</a>)</font><br />";

if (!isset($use))
{
if ($action == "readlog")
{
echo "<h2>Logfile contents:</h2><br/><pre>";
include($log_file);
echo "</pre>";
}
elseif($action == "viewsource") {
echo "<h2>Sourcecode of
".basename($_SERVER["PHP_SELF"])."</h2><br/></font>";
show_source(basename($_SERVER["PHP_SELF"]));
}
else
{
echo "<font class=\"bold\">&raquo;&nbsp;Current active
hostname:</font><font> ". @ gethostbyaddr($ipad[0][$current])."
(".$ipad[0][$current].")</font><br /><br />";
echo "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td
valign=\"top\"><font class=\"bold\">STATUS:</font></td><td
width=\"25\"></td><td valign=\"top\" width=\"25\"><font
class=\"bold\">IP:</font></td><td valign=\"top\" width=\"25\">&nbsp;</td><td
valign=\"top\"><font class=\"bold\">HOSTNAME:</font></td></tr>";
if ($action == "update")
{
if ($logging == "true") {
writefile($log_file,"[".$time."] (".$remoteuser."): USER
tried to update vhosts-file.\n", "a");
}
$endip++;
for ($i = $startip; $i < $endip; $i++) {
$ipvect[] = $ipserie.$i;
}

writefile($vhosts_file_tmp, "", "w");

for ($i = 0; $i < count($ipvect); $i++)
{
$ip = $ipvect[$i];
$hostname = @gethostbyaddr($ip);
$iprev = @gethostbyname($hostname);

if ($hostname == $ip) {
$hostname = "This IP is not reversed.";
$status = "<font class=\"red\">DOWN</font>";
} else {
if ($iprev != $ip) {
$status = "<font class=\"red\">DOWN</font>";
} else {
if ($iprev == $ip) {
$status = "<font class=\"green\">UP</font>";
} else {
$status = "ERROR";
}
}
}

if ($chrlimit == "true")
{
if (strlen($hostname) > $chrlength)
$hostname = substr($hostname, 0, $chrlength)."...";
}
$output = "<a href=\"?action=activate&amp;use=$ip\"
onmouseover=\"window.status='Set outgoing hostname to $hostname
($ip)';return true\" onmouseout=\"window.status='';return true\"
target=\"_self\"><tr bgcolor=\"".$colors[$i % 2]."\"><td
valign=\"top\">$status</td><td width=\"25\"></td><td valign=\"top\"
width=\"25\"><font style=\"cursor: hand;\">$ip</font></td><td valign=\"top\"
width=\"25\">&nbsp;</td><td valign=\"top\"><font style=\"cursor:
hand;\">$hostname</font></td></tr></a>\n";
echo $output;
writefile($vhosts_file_tmp, $output, "a");
}
writefile($vhosts_file_tmp,"<!-- GENERATION COMPLETED AT:
".$time." -->", "a");
writefile($log_file,"[".$time."] (".$remoteuser."): Vhost-file
update attempt succesfull!\n", "a");

unlink($vhosts_file);
rename($vhosts_file_tmp, $vhosts_file);

} else
{
include($vhosts_file);
}
}
}

if ((isset($use)) && ($action == "activate"))
{
modconf($findpattern, $use, $squidconf, $squidpid);
if ($logging == "true")
{
writefile($log_file,"[".$time."] (".$remoteuser."): Changed FROM -
".$ipad[0][$current]." (". @ gethostbyaddr($ipad[0][$current]).") - TO -
".$use." (". @ gethostbyaddr($use).")\n", "a");
}
echo "<font class=\"bold\">&raquo;&nbsp;Current active
hostname:</font><font> ". @ gethostbyaddr($use)." (".$use.")</font><br /><br
/>";
echo "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td
valign=\"top\"><font class=\"bold\">STATUS:</font></td><td
width=\"25\"></td><td valign=\"top\" width=\"25\"><font
class=\"bold\">IP:</font></td><td valign=\"top\" width=\"25\">&nbsp;</td><td
valign=\"top\"><font class=\"bold\">HOSTNAME:</font></td></tr>";
include($vhosts_file);
}
?>
</table></body></html >
Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.