如何解决mysql的语法错误?

问题描述 投票:0回答:1

前提·我想实现什么

我尝试在 bash 上使用 MySQL 客户端执行 MySQL 的“GRANT”命令,但出现语法错误。看起来没问题。

测试环境

  • 我的笔记本电脑
    • M2 MacBook Air
  • Mac操作系统
    • 文图拉 13.6.4
  • 谷歌计算引擎
    • Linux 6.1.0-18-云-amd64
  • Debian
    • Debian 6.1.76-1 (2024-02-01) x86_64
  • MySQL
    • 8.0.36 适用于 x86_64 上的 Linux(MySQL 社区服务器 - GPL)
  • bash
    • BASH_COMPLETION_VERSINFO=(2 11)

我做了什么

**1。在 MySQL 客户端上启动并执行 **

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'localhost' -> IDENTIFIED BY 'password';

出现问题·错误消息

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-> IDENTIFIED BY 'password'' at line 1

仅此而已

我得到了错误。我该怎么办? 你能帮我一下吗?

mysql linux database debian
1个回答
0
投票

系统告诉您错误以

->
开头。如果您查看任何在线帮助,您会发现没有任何帮助告诉您该命令需要它。

因此,您应该尝试:

GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';
© www.soinside.com 2019 - 2024. All rights reserved.