Copy-pasting versus entering "alter user "root"#"localhost" identified by ..." - mysql

I've copied-pasted alter user "root"#"localhost" identified by "NEW PASSWORD"; into mysql>. The message is:
Query OK, 0 rows affected (0,00 sec)
But if I enter exactly the same command (tested several times!), the message is:
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 'indentified by "NEW PASSWORD"' at line 1
Why?

Please take a closer at the error the server returns; you're typing indentified instead of identified!

Related

MySql syntax error during user creation when there is no apparent error

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';

Unable to GRANT SELECT on user in MySQL

I initially posted a question regarding why I was given a syntax error message here. I then created the user usermail with (I admit I misused IDENTIFIED BY but I don't think it matters in this case:
mysql> CREATE USER 'usermail'#'127.0.0.1' IDENTIFIED BY 'usermail';
Query OK, 0 rows affected (0.02 sec)
I then retried what I was initially trying to run.
mysql> GRANT SELECT ON servermail.* TO 'usermail'#'127.0.0.1' IDENTIFIED BY 'mailpassword';
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 'mailpassword'' at line 1
mysql> GRANT SELECT ON servermail.* TO 'usermail' IDENTIFIED BY 'mailpassword';
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 'mailpassword'' at line 1
mysql> GRANT SELECT ON servermail.* TO 'usermail'#'127.0.0.1' IDENTIFIED BY 'mailpassword';
I am still getting the exact same error. How was my question a duplicate? Or did I not follow the directions properly?

MYSQL: Create and grant privileges only if user doesn't exist

I want to test if a user exists. If it does I should do nothing. If it doesn't I should create it and grant privileges.
The concept code that I came up with is this:
IF EXISTS(SELECT 1 FROM mysql.user WHERE user = 'web_service_user' AND host = '%') THEN
\! echo "EXISTS";
ELSE
\! echo "DOES NOT";
END IF;
Hower when I run this I get this output:
EXISTS
DOES NOT
ERROR 1064 (42000) at line 1 in file: 'test_conditional.sql': 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 'ELSE
END IF' at line 3
So how do I test (in a conditional) if a user exists?
I know of this: mysql create user if not exists
However I would need still need to check if the user "was just created" in order to know If I need to execute the grant statements.

Error 1064 while running PASSWORD function in mysql

I've been busting my ass from last two days to update authentication_string of my root user and mysql is throwing ERROR 1064 at my face. I've tried every option I could (of course except the correct one which I don't know XD. After logging in as ROOT, I tried this code.
mysql> UPDATE MYSQL.USER SET AUTHENTICATION_STRING = PASSWORD('OJ') WHERE `USER` = 'ROOT';
And I'm getting following 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 '('OJ') WHERE `USER` = 'ROOT'' at line 1
I can't figure out what's going wrong here.
Thank you.

Mysql period character in account names

Is it possible to use period character in MySQL account names? I checked the documentation and tried to google but haven't found any convincing info.
Yes, it's possible, but you'll have to escape the username with quotes (").
E.g.:
Without quotes:
MariaDB [(none)]> create user name.surname;
ERROR 1064 (42000): 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 '.surname' at line 1
With quotes:
MariaDB [(none)]> create user "name.surname";
Query OK, 0 rows affected (0.00 sec)
yes only and only if you are using quotes e.g.
create user "myuser.lastname"