Hello I installed MYSQL and Apache via XAMPP. And I am trying some codes from a textbook while Apace and MYSQL are running. I am trying to connect MYSQL with this code :

<?php
//connect to MySQL; note we’ve used our own parameters- you should use
//your own for hostname, user, and password
$connect = mysql_connect("localhost", "root", "mysqlpass") or
die ("Hey loser, check your server connection.");
//create the main database
mysql_create_db("wiley")
or die(mysql_error());
....

But I am getting this:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\test\createmovie.php on line 4
Hey loser, check your server connection.

Could you please tell me how to fix this situation?
Thanks..

Recommended Answers

All 8 Replies

Did you check to make sure you have a user named "root" with the password "mysqlpass"?

No, and I don't know how to check :S and I don't know how to create that user and password on MYSQL either.

If you don't have a MySQL user, then how were you planning on connecting to the database?

Google is your friend. Study up a bit, then if you're still having problems, come back here!

Thank you very much for helping me.I googled as you advised and I found the command to create user but... I wrote it at the starting of the php part of the code above and I tried something on Command line of Windows but none of them worked. Could you please tell me where to write this command so that a user could be created on MySql
Here is the code I found :

CREATE USER 'root'@'localhost' IDENTIFIED BY 'mysqlpass';

Thank you very much..

You have to have some sort of MySQL administration tool. There's something for the Windows Command Line, as well as other tools. Find those, install them, and enter that data in there.

You have to be able to enter queries into MySQL. Do your homework, and you should figure it out.

For the record, it's not homework :) I am just trying to learn :)

when you start out with mysql the username is root pass is null (there is no pass)

Member Avatar for diafol

As PG says, try this:

$connect = mysql_connect("localhost", "root", "") or die ("Hey loser, check your server connection.");

AS ballchain says, get an admin tool. Loads of free ones. phpMyAdmin is the usual one, but it can be a bit clunky if you're using it from your own computer. DOwnload and install something like SQLyog (community version) or Navicat (free version) or a plethora of others! This will give you a nicer experience than fiddling with the command line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.