0

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

/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

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

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

3
  • I'm not sure about MySQL, but in SQL, strings are enclosed in single quotes ', not double quotes ". Have you tried replacing all double quotes with single ones? Commented Mar 10, 2017 at 7:29
  • I have tried that, but I used piliapp.com/mysql-syntax-check to syntax check Commented Mar 10, 2017 at 7:49
  • changing it to quotes I get 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 li ne 1 Commented Mar 10, 2017 at 8:25

1 Answer 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.

Check the SQL_MODE, for example session value -

SELECT @@SESSION.sql_mode;

And change it if needed. More information - 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";
Sign up to request clarification or add additional context in comments.

3 Comments

returned mysql> SELECT @@SESSION.sql_mode; +--------------------+ | @@SESSION.sql_mode | +--------------------+ | | +--------------------+ 1 row in set (0.00 sec)
I have added some details in answer.
I can create the use now! But this happens when I try to read in values from env variables mysql> select User,Host from mysql.user; +-------------+---------------------------------+ | User | Host | +-------------+---------------------------------+ | $MYSQL_USER | % | | root | 127.0.0.1 | | root | ::1 | | root | localhost | | root | wordpress-mysql-403298046-915cl | +-------------+---------------------------------+)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.