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

Laravel入门遇MySQL错误:指定DEFINER用户'mysql.infoschema'@'localhost'不存在

Fixing "The user specified as a definer ('mysql.infoschema'@'localhost') does not exist" on macOS High Sierra (Homebrew MySQL)

Hey there, I’ve run into this exact definer error before with Homebrew-installed MySQL on older macOS versions, so let’s walk through how to fix it step by step:

Step 1: Stop the MySQL service first

First, we need to shut down MySQL to make changes safely:

brew services stop mysql

If that doesn’t work (e.g., older Homebrew setup), try:

mysql.server stop

Step 2: Start MySQL in safe mode (skip permission checks)

This lets us log in without needing valid credentials to fix the missing user:

mysqld_safe --skip-grant-tables &

The & runs it in the background so you can keep using the same terminal window.

Step 3: Log into MySQL without a password

Now connect to the MySQL server as root, no password required:

mysql -u root

Step 4: Create the missing mysql.infoschema user and set permissions

Run these SQL commands one by one inside the MySQL prompt:

-- Create the infoschema user (empty password is default for this system user)
CREATE USER 'mysql.infoschema'@'localhost' IDENTIFIED BY '';

-- Grant necessary SELECT permissions (this user only needs to read schema info)
GRANT SELECT ON *.* TO 'mysql.infoschema'@'localhost';

-- Refresh permissions to apply changes immediately
FLUSH PRIVILEGES;

Step 5: Exit MySQL and stop the safe-mode process

Type exit; to leave the MySQL prompt, then kill the safe-mode MySQL process:

pkill mysqld

Step 6: Restart MySQL normally

Start the service back up using Homebrew:

brew services start mysql

Step 7: Test if the error is gone

Log into MySQL again (use your root password if you have one set):

mysql -u root -p

Then run the command that was failing before:

SHOW DATABASES;

This should now work without the definer error.


If the above steps don’t work (nuclear option: reinitialize MySQL)

Warning: This will delete all your existing databases. Back up your data first!

  1. Stop the service:
    brew services stop mysql
    
  2. Back up your MySQL data directory:
    cp -r /usr/local/var/mysql /usr/local/var/mysql_backup
    
  3. Find your installed MySQL version with:
    brew info mysql
    
    Look for a line like usr/local/Cellar/mysql/8.0.36 – that’s your --basedir path.
  4. Initialize a fresh MySQL instance:
    mysqld --initialize --user=mysql --basedir=/usr/local/Cellar/mysql/[YOUR_VERSION] --datadir=/usr/local/var/mysql
    
  5. Start the service:
    brew services start mysql
    
  6. Find the temporary root password in the error log:
    cat /usr/local/var/mysql/$(hostname).err | grep temporary password
    
  7. Log in with that temporary password, then set a new root password:
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'your-new-password';
    
    After this, you can restore your backed-up databases if needed.

Why this happens

This error usually pops up when MySQL is updated via Homebrew, and the automatic upgrade process fails to create or update the system-level mysql.infoschema user (which is critical for querying database schemas). Manually creating the user fixes the permission mismatch that’s causing the error.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 06:34:11