Over the last day or so I'm not able to connect to a database through PHP. Here's what my code connecting to the database looks like
$con = mysqli_connect("localhost","root","password","database");
And here's the strange error.
PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'user'#'localhost' (using password: YES) in - on line 2
I'd usually get that error if the credentials are incorrect, but I used a GUI and tested the connection with the exact credentials, where therefore means that, that is not the issue. I just started randomly getting this error and have restarted my computer, reinstalled MySQL, and reconfigure the server I've also tried 127.0.0.1 instead of localhost I'm on localhost so I have full control on pretty much anything and I didn't mess with anything causing this issue. Any ideas?
For some reason the function is trying to connect using the "user" user instead of "root".
You can debug further by adding the error link:
$con= mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($con));
Maybe the problem is in mysql server configuration.
You can try to change password and after flush privileges.
Than restart mysql!
Hope this helps! Bye.
I had the same problem as the title of this question, so incase anyone else googles upon this question and wants to start MySql in 'skip-grant-tables' mode on Windows, here is what I did.
Stop the MySQL service through Administrator tools, Services.
Modify the my.ini configuration file (assuming default paths)
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
In the SERVER SECTION, under [mysqld], add the following line:
skip-grant-tables
so that you have
# SERVER SECTION
# ----------------------------------------------------------------------
#
#The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
skip-grant-tables
Start the service again and you should be able to log into your database without a password.
Related
I recently copied my mysql db into a new data directory and changed a few settings.
I also accidentally deleted my user directory /home/user and had all the fun of the fair recreating that.
I can now connect to mysql on the command line but cannot connect via phpMyAdmin.
I get the message:
Cannot log in to the MySQL server
I have seen this before, but not without the error code #1045 or #2002 prepended.
Would there be any logs or documentation anywhere about this message without an error code?
UPDATE
phpMyAdmin is installed on the same server and prompts the web user for a username/password in the browser login page, on submit with the correct details it returns to this login page with the error message displayed.
I have tried changing the /etc/phpMyAdmin/config.inc.php line to:
$cfg['Servers'][$i]['host'] = '127.0.0.1'; // previously 'localhost'
I have also tried FLUSH PRIVILEGE to no avail.
According to me the following can be the issue and the ways to resolve it
Causes:
--> path to save php_session is not set or is uncorrectly set:
--> Either php do not have sufficient rights to write to session directory or the directory does not exists.
Solution:
To define the php_session directory add the below line to php.ini file:
session.save_path="/tmp/php_session/"
And give the write rights to the http server.
Mostly, the http server run as user daemon in group daemon. For this case, the following commands will do the work for you :
chown -R :daemon /tmp/php_session
chmod -R g+wr /tmp/php_session
restart http server.
Try it out and let me know
UPDATE
I have found this:-
In some rare cases, if your MySQL process has existed for a long time without any updates to your password, it may be storing your password in a format phpMyAdmin can't authenticate against. This will cause you to be unable to log in via phpMyAdmin, even with the correct username and password. In these cases, it is usually sufficient to change your MySQL password by another means (e.g. the command line), even if you "change" the password to the same thing.
so try just resetting your password through command line as
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
Finally fixed it, after much confusion.
Turns out, my my.cnf file was binding the address to our server's internal network IP.
bind-address = 192.168.etc
Previously, before moving the database (and socket location), it was also connecting with 'localhost' correctly (which uses the socket) and allowing login from phpMyAdmin.
After moving the db, the socket connection didn't work, and changing the config.inc.php line to 127.0.0.1 from localhost causes mysql to connect with TCP instead of the socket. This now caused conflict with the bind-address:
$cfg['Servers'][$i]['host'] = '127.0.0.1'; // previously 'localhost'
Removing the bind-address restriction allowed me to login.
A better solution however, was of course to fix the socket connection.
After fussing over permissions for a while, and asking around, someone help me find a setting in mysqli.ini (the extension phpMyAdmin uses to connect to the db):
mysqli.default_socket = /new/location
This fixed the localhost socket connection and I could reinstate my my.cnf bind-address and revert config.inc.php to use 'localhost' again.
in my situation, I just switch the php version from:5.6.16 to 7.0
and then it got login to nothing.
just switch it back, maybe reboot server it will support work in PHP 7.0
When I try to access the PhpMyAdmin page, I had the error in the title above.
I tried all procedures found in the internet but unfortunately I didn't found the resolution.
Below the error that I have :
phpMyAdmin tried to connect to the MySQL server, and the server
rejected the connection. You should check the host, username and
password in your configuration and make sure that they correspond to
the information given by the administrator of the MySQL server.
Edit:
Ichecked the Mysql service and I found that is not running, I try to start it but it won't.
I restart the machine and the things return to normal !! but when I edit the My.ini file in order to clean all added entries and restarted Mysql I had the same error and when I added skip-grant-tables option under [mysqld] in My.ini file I had once again access to Mysql !!!
I guess there is an issue in users or privileges !?
I am running phpMyAdmin on an amazon EC2 ubuntu lamp stack, configured to use a remote RDS server.
I have run the sudo dpkg-reconfigure phpmyadmin configuration script, accessed RDS using the master username and master password (not rdsadmin but that set on initialisation), and can log into the phpMyAdmin console.
However, every refresh of the phpMyAdmin interface creates a new failed connection. In the logs I see:
2014-01-14 23:42:20 12879 [Warning] Access denied for user
'phpmyadmin'#'[IP address]' (using password: YES)
What is the best way to try and debug this?
SOLVED
For reference, when using EC2 with RDS and the phpmyadmin installation wizard above, the control user is set to use an unresolvable host, such as ip-[EC2 IP ADDRESS].eu-west-1.compute.internal. Simply changing the host to your actual EC2 IP address allows the connection to become valid and failed connections no longer occur.
This may be because you've configured a controluser in your config.inc.php file (naming the controluser 'phpmyadmin'), but that isn't actually a valid user on the server. If that's the case, you could resolve it by either removing that line from the configuration or creating the user using the script provided (normally in the "examples" folder, but who knows where it is in the Ubuntu file system).
Try grep phpmyadmin config.inc.php on the configuration file and see if anything interesting is found.
Though, come to think of it, normally Ubuntu handles that sort of thing for you, so it's possible you've got a larger misconfiguration going on here. I'd also try reconfiguring it (dpkg-reconfigure --plow phpmyadmin) and see if you can get any further.
Are there any error or warning messages displayed within phpMyAdmin?
Did you add the EC2 ip address to the RDS security group ?
Check this a similar link Using PHPMyAdmin to administer Amazon RDS
Thanks
everyone. I'm a student and very inexperience newbie with PHP . Before you mark this as irrelevant or duplicate or anything. Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla
uploaded all the files to the server side public html and tried to run the file in browser
by using: my_school_link/my_username/
and I have this error
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
<?php
mysql_connect('host_name', 'user_name', 'password');
mysql_select_db('my_database_name');
?>
I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock*
and I have tried the following
view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers)
have entered the correct hostname, username and password
run as admin
checked if mysql is running ( it is so is Apache)
MySQL socket specified in php.ini was never edited so it is in default mode
cant locate mysql config file, or my.cnf, or etc folder
What could the problem be? Please if anyone could help me, please tell me what's wrong.
Please provide a step-by-step guide. and file extensions if need to save files....
Is there any additional things i can add to help anyone understand my problem better?
if yes, please let me know...this is my last resort so Thank you so very much in advance for any help.
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
This error appear when your mysql server is not running. If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.)
If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
Another reason may be that you are using the wrong host name while connect.
Don't use mysql_connect it is deprecated and instead you should use MySqli
I'm trying to get a wordpress local install working on my Mac.
I've recently set up a database, username and password using the MySQL client as per the instructions in the wordpress codex. That part is ok.
When I go to the local site on my computer I'm prompted by wordpress to set up the wp-config.php file. Putting in the same details that definitely work with the MySQL client returns an error.
Manually updating these details in the 'wp-config-sample.php' file and renaming it as 'wp-config.php' also doesn't work - I'm now greeted with a big bold message: "Error establishing a database connection".
From what I can gather, php and mysql are not communicating with each other properly.
I've changed the apache 2 configuration file found in 'etc/apache2/httpd.conf' and uncommented the line which loads the php5 module: LoadModule php5_module libexec/apache2/libphp5.so
and restarted the apache server. This has still not fixed my problem. I'm stuck on what to do next... help appreciated please!
It's been fixed now.
php was looking in the wrong place for the mysql.sock file, and couldn't communicate with the mysql database, meaning wordpress couldn't be set up.
On the command line I typed
ps aux | grep mysql
to bring up as much info about mysql that I could. From this I saw that the mysql socket on my computer is being used at /tmp/mysql.sock
Meanwhile, in the "wp-config.php" file, I changed the line define('WP_DEBUG', false); to define('WP_DEBUG', true); and refreshed my web browser that was showing my localhost setup. This now said a lot more info than "Error establishing a database connection" - infact I could see that the mysql.sock was not configured correctly at all.
Creating a 'phpinfo.php' file with just the single line of code <?php phpinfo(); ?> was the pivotal turning point for me.
Putting that 'phpinfo.php' file in my localhost directory and then viewing it from my web browser not only definitely confirmed that the mysql.sock file was not configured properly, but it also showed where the configurations were being loaded from on my machine: '/private/etc/php.ini'
The next thing I did was open up the 'php.ini' file in a text editor and doing a quick find and replace to update the correct location of mysql.sock.
Finally, a restart of the local apache server needed to be done to fully update all the new settings that I'd been fiddling about with.
sudo apachectl restart
Now everything works fine!
The Error-Message "Error establishing a database connection" indicates clearly, that the php-script can not establish the connection. This can have one of the following reasons:
Your host in the wp-config.php is not correct.
The mysql-server does not listen on that host
The user you set up in the mysql has no privileges to connect the way you are trying
The firewall blocks the access of the php-script to your mysql-host
Try to connect the database with the same settings of your wordpress using Sequel Pro (or any other GUI to connect a mysql database). If the connection works, the problem 2. and 3. isn't your problem.
Look in your firewall-log to make sure 4. is also not your problem.
If all problems are excluded (even 1. after a final check), try to run something like phpMyAdmin to connect your database, to make sure your php-installation has the needed drivers.