错误1064(42000):错误1064(42000):您的SQL语法有错误;

时间:2020-10-16 22:21:19

标签: mysql

我创建了一个新用户,但无法授予访问权限。但是我可以使用新用户“ apple.2”登录到mysql,但无法授予它访问权限或创建数据库。我还有一个叫“苹果”的用户,但我不认为这是问题所在。

~$ mysql -u apple.2 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 215
Server version: 5.7.31-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> create database apple.2_class;
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 '.2_class' at line 1

mysql> grant all privileges on *.* to 'apple.2' identified by 'password';
ERROR 1045 (28000): Access denied for user 'apple.2'@'%' (using password: YES)

1 个答案:

答案 0 :(得分:0)

除非引用,否则数据库名称中没有.

create database `apple.2_class`;

数据库名称与用户名不同。您需要使用更高的priv用户(通常为root)才能将priv授予apple.2

开始创建用户,然后授予用户许可的实践。合并后的版本在MySQL-8.0中已经消失。

create user 'apple.2' identified by 'password';
grant all privileges on *.* to 'apple.2';