0

I have a small mariadb SQL initialization script that starts like this:

drop user if exists 'uslmonitor';
drop database if exists uslmonitordb;
create database uslmonitordb;

This fails with this error:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'if exists 'uslmonitor'' at line 1

I checked the version of mysql/mariadb on the box, and it says this:

mysql  Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1

Update:

Ok, I've upgraded my MariaDB to "10.1.21-MariaDB-1~jessie" (I love Docker), and my init script excerpt is now this:

drop user if exists 'uslmonitor';
drop database if exists uslmonitordb;

flush privileges;

create database uslmonitordb;
create user 'uslmonitor'@localhost identified by 'uslmonitor';

This is failing with:

ERROR 1396 (HY000) at line 7: Operation CREATE USER failed for 'uslmonitor'@'localhost'
1
  • I managed to resolve this. The key was that the "drop user" was dropping a DIFFERENT user, so the create still fails. After changing the drop to reference the name in the same format (also enclosing localhost in single quotes), this started working. Commented Mar 15, 2017 at 22:26

1 Answer 1

1

This is one of those cases where reading the error message gives the answer.

MySQL version 5.5 (with which the MariaDB you're using is compatible) doesn't let you say IF EXISTS on the DROP USER operation.

That didn't come in until version 5.7.8.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok. I'm using the latest version of mariadb available for centos 7.3, using the default yum repos, so I guess I'll have to research whether I can make it use a newer version.

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.