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

MySQL创建用户报错求助:@符号及BY关键字报错问题

Fixing MySQL User Creation & Grant Errors

Hey there! Let's break down why you're hitting those syntax errors and get your secure login user set up correctly.

Why Your Original Queries Failed

  1. Using double quotes (") around identifiers:
    By default, MySQL treats double quotes as string delimiters, not identifier wrappers. So when you wrote "sec_user"@'localhost', the database tried to parse "sec_user" as a string followed by @'localhost'—which is invalid syntax, hence the error at the @ symbol.

  2. Removing all quotes entirely:
    When you stripped all quotes, your query became CREATE USER sec_user@localhost IDENTIFIED BY '...';. MySQL interpreted sec_user@localhost as a single username (instead of splitting it into the username sec_user and host localhost). This messed up the syntax flow, leading to the error at the BY keyword.

The Correct Query

Use backticks (`) to wrap identifiers (usernames, database names) — this is MySQL's standard way to handle identifiers without needing to change any settings. Here's the fixed code:

CREATE USER `sec_user`@'localhost' IDENTIFIED BY 'eKcGZr59zAa2BEWU';
GRANT SELECT, INSERT, UPDATE ON `secure_login`.* TO `sec_user`@'localhost';

Quick Verification

After running these commands, you can confirm the user was created successfully with this check:

SELECT user, host FROM mysql.user WHERE user = 'sec_user';

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:23:07