MySQL and PHP is a love story that started long time ago. However the love story with MySQL 8.0 was a bit slower to start… but don’t worry it rules now !
The support of MySQL 8.0’s new default authentication method in PHP took some time and was added in PHP 7.2.8 and removed in PHP 7.2.11. but now it’s fully supported in PHP 7.4 !
If you have installed PHP 7.4, you can see that the new plugin
is now available:
# php -i | grep "Loaded plugins|PHP Version " | tail -n2 PHP Warning: Module 'mysql_xdevapi' already loaded in Unknown on line 0 PHP Version => 7.4.0 Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password, auth_plugin_mysql_clear_password, auth_plugin_caching_sha2_password, auth_plugin_sha256_password
So no need to create a user with
as authentication method in MySQL 8.0
In summary, if you want to use a more secure method to connect to your MySQL 8.0 form your PHP application, make sure you upgrade to PHP 7.4
The drawback of this new mysqli.so is that if you don’t modify the
and by adding a value to
, when you try to connect to MySQL on
without specifying the socket path, the connection will fail with the following message:
PHP Warning: mysqli::__construct(): (HY000/2002): No such file or directory in <name of your file>.php on line 45 An error occurred when trying to establish a connection to the database: Error #2002
You have then 2 solutions:
- add in
php.inia default value for
- or specify the socket path when you initiate the connection to MySQL using
mysqliin your code
This is also the default behavior on Ubuntu when using PHP 7.4 from ppa:ondrej/php repository.
Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN AND DEVELOPMENT.
PHP never ceases to surprise me with its built-in capabilities. These are a few of the functions I find most fascinating. 1. Levenshtein This function uses the Levenshtein algorithm to calculate the…
The Flight Tracker API provides developers with the ability to access real-time flight status, which is extremely useful for integrating historical tracking or live queries of air traffic into your…
JWT tokens are a standard used to create application access tokens, enabling user authentication in web applications. Specifically, it follows the RFC 7519 standard. What is a JWT token A JWT token…
What happens if we realise that a series of databases that we thought were optimised through the use of indexes, have begun to consume CPU usage time of a server…
The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a method for limiting the number of instances of an object to just one.…
In today’s article we will write about how to make a working form that upon hitting that submit button will be functional and send the email (to you as a…
This list of rules by no means is a sure bet to secure your web services, but it will help in preventing script-kiddings from doing some basic browsing around. MySQL injection…
PHP 8.0 has been released last November 26: let's discover together the main innovations that the new version introduces in this language. PHP is one of the most popular programming languages…
There are many ways to sort an array in PHP, the easiest being to use the sort() function built into PHP. This sort function is quick but has it's limitations,…
There are plenty of tutorials online, which won't cost you a cent. If you are sufficiently self-driven and interested, you have no difficulty training yourself. The point to learn coding…