You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter连接MySQL失败求助:MAMP环境下需调整哪些配置?

Fixing MySQL Access Denied Error with MAMP & CodeIgniter

Hey there, let’s work through this frustrating access denied error you’re hitting while using CodeIgniter with MAMP. Here are the key tweaks to get your database connection working:

1. Update CodeIgniter’s Database Port for MAMP

MAMP runs MySQL on port 8889 by default (not the standard 3306 most frameworks expect). Open your CodeIgniter database config file at application/config/database.php and set the correct port:

$db['default']['port'] = '8889';

2. Use 127.0.0.1 Instead of localhost as Hostname

MySQL sometimes treats localhost as a socket connection, but MAMP’s socket path might not align with CodeIgniter’s defaults. Switch your hostname to the loopback IP to force a TCP connection:

$db['default']['hostname'] = '127.0.0.1';

3. Verify User Permissions for the Correct Host

Even if you granted permissions to AliWalsh@localhost, you need to explicitly allow access for AliWalsh@127.0.0.1 (since we’re now connecting via IP). You can fix this in phpMyAdmin (accessible via MAMP’s control panel at http://localhost:8888/phpmyadmin/):

  • Go to the "User accounts" tab
  • Edit the AliWalsh user
  • Ensure permissions are set for both localhost and 127.0.0.1 (or use % for all hosts, fine for local development)

Alternatively, run this SQL query directly in phpMyAdmin’s SQL tab:

GRANT ALL PRIVILEGES ON *.* TO 'AliWalsh'@'127.0.0.1' IDENTIFIED BY 'your_password_here';
FLUSH PRIVILEGES;

4. Double-Check Credentials and Database Existence

It’s easy to miss a typo! Confirm:

  • The username in database.php exactly matches AliWalsh (case-sensitive on some systems)
  • The password has no extra spaces or typos
  • The database you’re trying to connect to actually exists in MAMP’s MySQL (check phpMyAdmin to verify)

5. Ensure MAMP’s MySQL Server is Running

Quick sanity check: Make sure the MySQL service is started in MAMP’s control panel. Sometimes it stops unexpectedly, so a restart can fix odd connection glitches.

After making these changes, reload your CodeIgniter news page—you should be able to connect to the database successfully!

内容的提问来源于stack exchange,提问作者A.Walsh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:27:04