Software:
PHP 7.3
MySQL Workbench 8.0
This is my PHP code:
try {
$link = mysqli_connect($DB_SERVER,$DB_USERNAME, $DB_PASSWORD,$DB_NAME,3306);
} catch (Exception $e){
throw new Exception("Can't execute command. ERROR: ".$e);
}
This is the error:
Warning: mysqli_connect(): PHP was built without openssl extension, can't send password encrypted in login.php on line 11
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'XXXXX_admin'#'localhost' (using password: YES) in C:\inetpub\wwwroot\ on line 11
PHP Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\inetpub\wwwroot\ on line 24
PHP Fatal error: Uncaught Exception: ERROR: Failed to connect to in C:\inetpub\wwwroot:24 Stack trace: #0 {main} thrown in C:\inetpub\wwwroot\ on line 24
Now the magic, when I login in to mysql workbench with the same user and password everything works fine. I have access to tables and other things. When I login in with my PHP application everything works also.
So my problem is everytime my server reboots I have to login in with MySQL Workbench, to get it working again. What am I missing?
You need to do verify few of the steps:
All necessary extensions are enabled like mysqli, openssl etc
Port is available
MySQLi is connecting at 3306 Port
Rest could be your username and password issue
Let us know once you will be verifying all above steps.
What you need to do is enable the openssl extension for php.
Open your php.ini file and search for the line:
;extension=php_openssl.dll
You need to uncomment it by removing the semicolon in front of it, leaving you with this:
extension=php_openssl.dll
Related
This question already has answers here:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
(17 answers)
Closed 2 years ago.
I'm totally stuck having spent a couple of days trying to figure this out...
I have set up an Apache web server (version 2.4.34) on my Mac OS running Mojave (10.14.3) and have installed the current version of MySQL Community Server (8.0.15). Both running perfectly as I can determine (from command line). I have PHP 7.1.23 installed. When I create a .php file with the following code and put it in my Sites directory and then in Safari go to http://localhost/~dave/hello.php I get this error:
"Warning: mysqli::__construct(): (HY000/2002): No such file or
directory in /Users/dave/Sites/hello.php on line 7 Connection failed:
No such file or directory".
Code in hello.php:
<?php
$servername = "localhost";
$username = "dave";
$password = "*****";
//Create connection
$conn = new mysqli($servername, $username, $password);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
I have tried everything I can think of, including those suggestions in the other two similar posts (this one: My database user exists, but I still get an (HY000/2002): No such file or directory and this one: PHP Warning: mysqli::__construct(): (HY000/2002): No such file or directory (Debian GNU/Linux 9)), and I cannot connect to MySQl with php. In particular, I checked with the php info page and the socket for mysqli is given as var/mysql/mysql.sock. In the relevant table in mysql the value for socket is given as /tmp/mysql.sock. I tried changing the php.ini.default file by adding each of these sockets (in place of the empty value) and neither worked (still generates the same error). I thought that the 2002 MySQL socket error might be the problem, so I made a symlink by doing this:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
but all that did was generate a new error:
Warning: mysqli::__construct(): The server requested authentication
method unknown to the client [caching_sha2_password] in
/Users/dave/Sites/hello.php on line 7
Warning: mysqli::__construct(): (HY000/2054): The server requested
authentication method unknown to the client in
/Users/dave/Sites/hello.php on line 7 Connection failed: The server
requested authentication method unknown to the client
So I removed the symlink...and returned to the original error.
I also tried replacing "localhost" with the IP address 127.0.0.1 as well as "localhost:3306" as other question threads have suggested. Nothing worked here either.
Please help, I am new to this kind of use of the computer/web design and I'm out of obvious (googleable/understandable) options.
Use 127.0.0.1 instead of localhost.
I got some help from some local tech guys in my area and it turns out that fixing the socket error was the first step, like I tried to do above. I eventually did it this way, using the solution by noun:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
The second error message was then generated (same one as in my question, here again):
mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /Users/dave/Sites/hello.php on line 7
Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /Users/dave/Sites/hello.php on line 7
This was fixed by the SQL-based solution (June 9 2018 answer) to this question:
php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
This SQL statement was simply run in MySQL from the terminal. After restarting the Apache server I reloaded the .php file in Safari and this resulted in a successful mysqli connection to MySQL with PHP. I also tried a PDO connection and this also worked.
I have MySql 8.0 freshly server installed. Initially, I was able to log in, but when I tried to connect to it through PHP PDO I got this error:
Fatal error: Uncaught PDOException: PDO::__construct(): The server
requested "authentication method unknown to the client
[caching_sha2_password]"
I read from StackOverflow a solution here
Open your my.cnf (in my case the my.ini file) and add the following
entry (and restart MySQL)
[mysqld]
default_authentication_plugin=mysql_native_password
Create a user (your MYSQL_USER name) using the correct 8.0 syntax for
generating the password (see below) <---- Altered my existing user
"root"
IDENTIFIED WITH mysql_native_password
Flush the privileges and try again.
After I restarted the MySql service I'm now unable to log in to MySQL. with it saying this error now:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: YES)
I want to be able to log in through PHP PDO, but I can't even log back in through regular command prompt or MySQL Workbench. Any help on this would be great.
I've upgraded from a 6 year old Xampp to the next latest one:
xampp-win32-7.0.23-0-VC14-installer.exe
Before install I did a Mysql Dump All:
mysqldump -u root -p --all-databases > all-db-dump.sql
After install I Imported that all-db-dump.sql from phpMyAdmin.
When starting my PHP-application filmtv.php I get the above errors, see attached filmtv.php.png.
Look at the source samples and I hope someone out there have an idea of whats wrong, cause I expected it to work smoothly without having to change my application.
Also, if I do a minor change using phpMyAdmin like adding a new user then I cannot use phpMyAdmin anymore it'll respond that user/pwd is incorrect, very strange. Up to now I've done 5 re-installs because of that.
From phpMyAdmin user:
root localhost Yes ALL PRIVILEGES
filmtv.php
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\css\bertil.php on line 2
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\css\bertil.php on line 3
Fatal error: Uncaught Error: Call to undefined function mysql_error() in C:\xampp\htdocs\filmtv.php:156 Stack trace: #0 {main} thrown in C:\xampp\htdocs\filmtv.php on line 156
filmtv.php includes
include 'css/adam.php';
include 'css/bertil.php';
if (!$cxn) { echo "Unable to connect to DB: " . mysql_error();
exit;}
Source-code:
*adam.php:*
<?php
$user="root";
$host="localhost";
$password="tenthirty";
$database = "ljung";
?
*bertil.php:*
<?php
$cxn = mysqli_connect($host,$user,$password,$database);
$cxu = mysqli_connect($host,$user,$password,$database);
?>
_By the way, my Xampp install is:
Includes: Apache 2.4.27, MariaDB 10.1.26, PHP 7.0.23, phpMyAdmin 4.7.4, OpenSSL 1.0.2, XAMPP Control Panel 3.2.2, Webalizer 2.23-04, Mercury Mail Transport System 4.63, FileZilla FTP Server 0.9.41, Tomcat 7.0.56 (with mod_proxy_ajp as connector), Strawberry Perl 7.0.56 Portable_
_
Cheers,
Torbjorn
Stockholm
In the newest version of Xampp they start to use mariadb instead of mysql
so you can't log in as root user so you have to create new user and grant your privileges in that user
Ive set up phpmyadmin and mySql on my windows server but when i try to connect via php i get this error :
Warning: mysqli::mysqli(): MySQL server has gone away in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Warning: mysqli::mysqli(): Error while reading greeting packet. PID=15852 in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Warning: mysqli::mysqli(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Catchable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 14
I know by default mySql only allows local connections but following tutorials online they are all saying to uncomment a line in a "my.ini" file. All i have in my sql folder is a my-default.ini with the following :
How can i open this up to connections from an external php script?
Try adding this to your php.ini:
mysqli.reconnect = 1
I have problem when I wanted to put website to hosting. I am using nette and when I want to connect I get error
PDO::__construct(): Premature end of data (mysqlnd_wireprotocol.c:553)
I am using nette framework with this db config:
dsn: 'mysql:host=dbhost;dbname=dbtable'
user: dbuser
password: dbpass
When I have tried classic connection, it is working correctly. I am not sure what to do and how to solve this.
if($myslConnection = mysql_connect("dbhost", "dbuser", "dbpass")){
echo("connected");
mysql_select_db("dbtable",$myslConnection);
$result = mysql_query("SELECT * FROM news", $myslConnection);
while($resultItem = MySQL_Fetch_Row($result)){
echo $resultItem[1]."<br>";
}
}
else{
exit("not connected");
}
edit: error what I have got
Warning: PDO::__construct() [pdo.--construct]: Premature end of data (mysqlnd_wireprotocol.c:553) in /var/www/html/unix/i/y/domainname.noveranet.cz/www/info.php on line 5
Warning: PDO::__construct() [pdo.--construct]: OK packet 1 bytes shorter than expected in /var/www/html/unix/i/y/domainname.noveranet.cz/www/info.php on line 5
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file' in /var/www/html/unix/i/y/domainname.noveranet.cz/www/info.php:5 Stack trace: #0 /var/www/html/unix/i/y/domainname.noveranet.cz/www/info.php(5): PDO->__construct('mysql:host=tran...', 'user', 'pass') #1 {main} thrown in /var/www/html/unix/i/y/domainname.noveranet.cz/www/info.php on line 5