You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Laragon创建Laravel项目时未用MySQL密码致权限拒绝,如何配置密码?

Fixing "Access Denied" Error: Setting MySQL Password in Laragon

Got it, let's walk through how to set a MySQL password in Laragon to resolve that "Access denied for user 'root'@'localhost' (using password: NO)" error. This is a super common hiccup, and it's straightforward to fix:

Step 1: Stop All Laragon Services

First, make sure Laragon is running, then click the Stop All button in the Laragon toolbar to shut down Apache and MySQL completely.

Step 2: Start MySQL in Safe Mode

  • Click the Laragon icon in your system tray to open the main menu.
  • Hover over MySQL > select Start Safe Mode (this launches MySQL without requiring password authentication, so we can modify the root password).

Step 3: Connect to MySQL and Set a New Password

  • Open Laragon's built-in terminal (click the Terminal button in the toolbar, or right-click the Laragon tray icon > Terminal).
  • Run this command to log into MySQL without a password:
    mysql -u root
    
  • Once you're in the MySQL shell, run these queries to set your new password (replace your_secure_password with the password you want):
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_secure_password';
    FLUSH PRIVILEGES;
    
  • Type exit and press Enter to leave the MySQL shell.

Step 4: Restart MySQL Normally

  • Go back to the Laragon tray menu, hover over MySQL > select Stop Safe Mode.
  • Click Start All in the Laragon toolbar to restart all services with your new password active.

Step 5: Update Laravel's Database Config

Don't forget to update your Laravel project's .env file to use the new password—this is crucial for Laravel to connect to the database:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=your_secure_password

That should get rid of the access denied error and let Laragon create your Laravel project with the correct database credentials.

内容的提问来源于stack exchange,提问作者ebillis

火山引擎 最新活动