I have a brand new mysql installation. I want to delete a user only if exists and I have only root user. I'm trying to run from shell:
DROP USER IF EXISTS foo;
or
DROP USER IF EXISTS 'foo'#'localhost';
But mysql returns this kind of messages:
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 'IF EXISTS foo' at line 1
What am I doing wrong?
I read this post but does not explain why IF EXISTS statement does not work
From your own link:
As of MySQL 5.7.8, the IF EXISTS clause can be used, which causes the
statement to produce a warning for each named account that does not
exist, rather than an error.
You can find out your server version with e.g.:
select ##version;
Related
i'm trying to do a forward engineering and at the end it gaves me this error
"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 'IF EXISTS Amministrazione' at line 1"
SQL Code: DROP USER IF EXISTS Amministrazione
This is the code:
SET SQL_MODE = '';
DROP USER IF EXISTS Amministrazione;
SET SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
CREATE USER 'Amministrazione' IDENTIFIED BY 'amministrazione';
GRANT EXECUTE ON procedure `GestioneCorsiDiLingue`.`Generare report Insegnante Mensile` TO 'Amministrazione';
GRANT EXECUTE ON procedure `GestioneCorsiDiLingue`.`Elimina Corso` TO 'Amministrazione';
GRANT EXECUTE ON procedure `GestioneCorsiDiLingue`.`Aggiunta Insegnante` TO 'Amministrazione';
GRANT EXECUTE ON procedure `GestioneCorsiDiLingue`.`Elimina Insegnante` TO 'Amministrazione';
GRANT EXECUTE ON procedure `GestioneCorsiDiLingue`.`Creazione corso` TO 'Amministrazione';
GRANT EXECUTE ON procedure `GestioneCorsiDiLingue`.`Assegnazione insegnanti a corso` TO 'Amministrazione';
if you can please help me it would be great because i can't really figure out what's the problem, if you need further details just ask me!
The best solution to solve this error is to upgrade to MySQL 5.7 (or later).
The "IF EXISTS" option for DROP USER was not supported before MySQL 5.7. If your MySQL Server is an earlier version, that syntax will return error 1064.
You can use DROP USER in older versions of MySQL, but not DROP USER IF EXISTS.
I'm talking about the version of MySQL Server, regardless of the version of the client like MySQL Workbench. The SQL syntax you can use is that which is supported by the server.
You can verify your MySQL Server version:
SELECT ##version;
P.S. MySQL 5.6 reached its end-of-life as of 2021-02-05 (that is, yesterday as I post this). So you should upgrade anyway.
I'm trying to install Moodle using Ubuntu using the following guide: Step-by-step Installation Guide for Ubuntu
I'm currently on step 6 where I have to create a mySQL user with the correct permissions and this is where I'm getting stuck.
The 1st command - create user 'user1'#'localhost' IDENTIFIED BY 'password1'; works fine
However the 2nd command -
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO user1#localhost
IDENTIFIED BY 'password1';
Returns the error message - 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 'password1'' at line 1
The installation manual mentions that this may be a problem so advises me to use - SELECT password('password1'); in order to get a hash value to overcome the problem.
However instead of giving me a hash value it comes up with the same error of - 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 '('password1')' at line 1
I am a beginner to all this so I'd appreciate any responses, thanks in advance!
You need apostrophes around the name and the host in your command, like:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'user1'#'localhost'
IDENTIFIED BY 'password1';
EDIT
According to the comments, slightly changing the command fixed the syntax error:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'user1'#'localhost';
First Create user ‘moodleuser’#’localhost’ identified by ‘yourpassword’;
Then grant select,insert,update,delete,create,create temporary tables,drop,index,alter on moodle.* to 'moodleuser'#'localhost';
I try to install fleetspeak. Use Ubuntu 18.04.
First of all I run this
CREATE USER 'fleetspeak-user' IDENTIFIED BY 'fleetspeak-password';
Then I want to create database with this
CREATE DATABASE 'fleetspeak';
But has an error:
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 ''fleetspeak'' at line 1
Why I can get this?
Try the create database script without single quotes in dbname
CREATE DATABASE fleetspeak;
Error with dropping tables:
SQL query:
DROP user IF EXISTS 's01'#'%';
MySQL said: Documentation
#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 'if exists 's01'#'%'' at line 1
Error without dropping tables:
SQL query:
/*Students*/ CREATE User 's01'#'%' IDENTIFIED BY 'pw1';
MySQL said: Documentation
#1396 - Operation CREATE USER failed for 's01'#'%'
Example of some of my code:
Drop user if exists 's01'#'%';
flush privileges;
/*Students*/
Create User 's01'#'%' Identified by 'pw1';
I don't exactly know what is wrong. I looked it up and it said add flush privileges, but I still get the same two errors.
Check your version of mysql with select version();. The IF EXISTS option for DROP USER was added in 5.7. If you're not using 5.7, then that likely explains your first error.
Check if the user exists by querying mysql.user table.
select user, host from mysql.user where user = 's01';
Also since you are not specifying a hostname, just execute
DROP user IF EXISTS 's01';
Create User 's01' Identified by 'pw1';
The wildcard host (#'%') is implied.
Also execute SHOW GRANTS to verify that your user has the correct privileges to create and drop users.
I have an error in my MySQL statement (using shell file), which I can't seem to resolve. Tried to put quotes etc but no luck. When I created it using phpmyadmin it works, but I want to have it scripted. Must be something small... Any ideas?
--- Create mySQL database ---
CREATE DATABASE IF NOT EXISTS _test-123;
CREATE USER 'test-123'#localhost IDENTIFIED BY '***';
GRANT ALL PRIVILEGES ON _test-123.* TO 'test-123'#'localhost';
FLUSH PRIVILEGES;
Enter password:
ERROR 1064 (42000) at line 1: 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 '-123' at line 1
Try removing the "-" and do this one instead-
CREATE DATABASE IF NOT EXISTS _test_123;