mysql access denied

Asked by pdo100

Is there anyone who can help me resolving this problem?

I get the message every time I try mysql with php
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'prajakta'@'localhost' (using password: YES) in /var/www/insert.php on line 2
Could not connect: Access denied for user 'prajakta'@'localhost' (using password: YES)

I assign root password and once I type:
~: mysql -u root -p
~: password: ******

 i get logged in.i can create my own database,table everything.but when i connect it with php i get the error mentioned above.plz help me.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
pdo100
Solved:
Last query:
Last reply:
Revision history for this message
Dr Paul Brewer (drpaulbrewer) said :
#1

1. Well, the error 1045 is usually generated by being root and typing

mysql

or, by being another user, and typing

mysql -u root.

Note the error says (using password: NO). This means a password was not entered.

2. The next command you used 'mysql -u root -p ' will ask for a password before attempting to contact the server,
and will not generate the error 1045 you saw.

The new error, 2002, says that it can not connect. This can be generated when the MySQL server is not running
or is not accessible for some other reason.

You can check to see if mysql is running by typing

ps aux | grep mysql

When it is running, the output should show a long command line being run by user mysql/
When it is not running, that will not be there.

You can usually start mysql if it is not running, by typing
sudo /etc/init.d/mysql start

If that says [OK], then it started.
If that says [FAIL], then something is wrong.

It is impossible to tell at this stage if your MySQL is badly installed, or if it can be fixed.
It may be ok. The problems you mention are common when first starting out, as it can be
a bit overwhelming at first.

This is all the time I can personally spare. Perhaps if you still have trouble,
another person will be able to respond.

Good luck!

Paul

Revision history for this message
pdo100 (piotrdomowicz) said :
#2

I have solved the problem and to help other with the same problem I describe the way I did it:

Go to terminal and log in as root. Follow the command:
~ su root
~ password: ******

You are as root now.
For you to better understand locations go to system folder by typing:
~ cd /

Next find out where is a my.conf file.
On my machine it is located in /etc/mysql/ folder so the next commands will refer to this folder.
Next you type following command:
~ sudo gedit /etc/mysql/my.cnf

It will open my.cnf file via gedit and you will be able to modify it.
In my.cnf file find line with following statement:
[mysqld]
just underneath this line type in:
skip-grant-tables
and save it

Now restart mysql typing
~ killall mysqld
once it stopped restart it with:
~ mysqld

You should be able to access mysql with no problem,
type for fresh users who didn't set up root password yet:
~ mysql -u root mysql

Then you will get couple of lines of info
then you are in mysql

Now to set up root password type:
mysql> UPDATE mysql.user SET Password=PASSWORD (“yournewpassword”)
        -> WHERE User=”root”;
You will get 2 lines saying it was successfully done
then type:
mysql> FLUSH PRIVILEGES;

I hope it will help resolving this annoying problem that I had couple of days ago and couldn't find the answer... Now it works on my machine so I hope it will help others.

Revision history for this message
mith (mithilesh-0210) said :
#3

I m using Ubuntu.
I have installed MYSQL.
I have created a database named ROOM
from mysql I m not able to access file outside of /var/lib/mysql/
I use the following mysql cmd
mysql> select load_file("/var/lib/mysql/app_user.txt");
This shows the content of the file.

If I copy the file in the location /var/lib/
and use the cmd
mysql> select load_file("/var/lib/app_user.txt");

It displays
load_file("/var/lib/app_user.txt")
NULL
1 row is set

the file is created by root and group is root.
The chmod of the file is 777.

Please help