Phalcon官网Demo报错SQLSTATE[HY000][2054]:客户端不支持服务器认证方法
Hey there, I’ve hit this exact error before when spinning up Phalcon’s official demo with MySQL 8.x—let me break down what’s happening and how to fix it quickly.
Why this happens
MySQL 8.0 and newer use caching_sha2_password as the default authentication plugin for user accounts. But older versions of PHP’s MySQL extensions (mysqli or PDO_MySQL) don’t support this newer auth method, and since Phalcon relies on these extensions to connect to the database, you get that frustrating error.
Solution 1: Update the MySQL user’s authentication method (most common fix)
This is the easiest approach for local development setups:
- Log into your MySQL server via the command line using a root account:
mysql -u root -p - Switch to the
mysqlsystem database:USE mysql; - Alter the user account your Phalcon demo uses to use the older, compatible
mysql_native_passwordplugin. Replacephalcon_userandyour_passwordwith the actual credentials from your demo’s config:ALTER USER 'phalcon_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password'; - Flush MySQL’s privileges to apply the change immediately:
FLUSH PRIVILEGES; - Exit MySQL, restart your web server (like Apache or Nginx) and Phalcon’s demo application—then try loading the demo again.
Solution 2: Ensure PHP extensions support the new auth method (for production)
If you’re working in a production environment and don’t want to downgrade the auth method, make sure:
- You’re running PHP 7.4 or newer (these versions include updated MySQL extensions that support
caching_sha2_password) - Your
mysqliandPDO_MySQLextensions are compiled with support for the new auth plugin - In your Phalcon database config, double-check that you’ve set the charset to
utf8mb4(this often helps with compatibility)
Quick sanity check
Before trying anything else, confirm that your Phalcon demo’s database config file (usually something like config/database.php) has the correct username, password, and host—typos here can sometimes throw similar errors too!
内容的提问来源于stack exchange,提问作者dawnchen

