创建用户时出现错误的mysql语法错误

时间:2021-09-23 15:37:47

I'm using a list of sql statements in a text file to bootstrap mysql before actually starting it, the command is as follows

我在文本文件中使用sql语句列表来引导mysql,然后才真正启动它,命令如下

/usr/sbin/mysqld --user=mysql --bootstrap --verbose=0 < $tfile && echo "Successfully run $tfile"

And the SQL statements, to update the root users password and create a wordpress users in the $tfile are

和SQL语句一样,更新root用户密码并在$ tfile中创建一个wordpress用户

USE mysql;
FLUSH PRIVILEGES;
CREATE USER "root"@"%" IDENTIFIED BY "1234567890abcdef";
GRANT ALL PRIVILEGES ON *.* TO "root"@"%" WITH GRANT OPTION;
UPDATE user SET password=PASSWORD("1234567890abcdef") WHERE user="root";
GRANT ALL PRIVILEGES ON *.* TO "root"@"localhost" WITH GRANT OPTION;
UPDATE user SET password=PASSWORD(") WHERE user="root" AND host="localhost";
CREATE DATABASE IF NOT EXISTS `wordpress` CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER "wordpress"@"%" IDENTIFIED BY "1234567890abcdef";
GRANT ALL PRIVILEGES ON *.* TO "wordpress"@"%" WITH GRANT OPTION;

However no matter how K tweak this, I come back to the same error

但无论K如何调整,我都会回到同样的错误

ERROR: 1064 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 '1234567890abcdef' at line 1 [ERROR] Aborting

错误:1064您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行的“1234567890abcdef”附近使用正确的语法[ERROR]正在中止

1 个解决方案

#1


1  

In simple mode, MySQL treats " as a literal quote, but if ANSI_QUOTES is enabled, then it is used as quote symbol for identifiers.

在简单模式下,MySQL将“视为文字引用,但如果启用ANSI_QUOTES,则将其用作标识符的引号。

Check the SQL_MODE, for example session value -

检查SQL_MODE,例如会话值 -

SELECT @@SESSION.sql_mode;

And change it if needed. More information - ANSI_QUOTES.

如果需要,可以改变它。更多信息 - ANSI_QUOTES。


Try to change this mode before the script -

尝试在脚本之前更改此模式 -

-- SET @@SESSION.sql_mode = 'ANSI_QUOTES';
SET @@SESSION.sql_mode = '';
USE mysql;
FLUSH PRIVILEGES;
CREATE USER "root"@"%" IDENTIFIED BY "1234567890abcdef";

#1


1  

In simple mode, MySQL treats " as a literal quote, but if ANSI_QUOTES is enabled, then it is used as quote symbol for identifiers.

在简单模式下,MySQL将“视为文字引用,但如果启用ANSI_QUOTES,则将其用作标识符的引号。

Check the SQL_MODE, for example session value -

检查SQL_MODE,例如会话值 -

SELECT @@SESSION.sql_mode;

And change it if needed. More information - ANSI_QUOTES.

如果需要,可以改变它。更多信息 - ANSI_QUOTES。


Try to change this mode before the script -

尝试在脚本之前更改此模式 -

-- SET @@SESSION.sql_mode = 'ANSI_QUOTES';
SET @@SESSION.sql_mode = '';
USE mysql;
FLUSH PRIVILEGES;
CREATE USER "root"@"%" IDENTIFIED BY "1234567890abcdef";