Please I'm a newbie and i'm using the alain Beaulieu book 'Learning SQL' and on the first tutorial we need to add this function after creating the database 'bank'.
I have created it and typed the code but the shell returns the error after this code :
mysql> grant all privileges on bank.* to 'lrngsql'#'localhost' identified by 'xyz';
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 'xyz'' at line 1
I didn't find anyone speaking about this problem, so I hope someone could help
In older versions of MySQL you could use IDENTIFIED BY in a GRANT statement to change passwords or event create accounts. Newer versions do not have this option. Adding a user and granting it privileges are two separate things and therefore have to be done in two different statements.
Try
CREATE USER 'lrngsql'#'localhost' identified by 'xyz';
GRANT ALL PRIVILEGES ON bank.* TO 'lrngsql'#'localhost';
For more information have a look at the documentation for GRANT and CREATE USER.
Related
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 am using mysql version 8.0
From mysql cli I am trying to call the function PASSWORD. So I have used the following command :
mysql > select PASSWORD('123');
But I get the following error in this case :
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 '('123')' at line 1
I have also tries the following :
mysql > select PASSWORD("123");
mysql > select PASSWORD(`123`);
But each one give the same error. I have also googled a lot but could not find any solution for this.
How can I solve this
Regards,
Tanvir
As mysql documentation on the password() function says:
This function was removed in MySQL 8.0.11.
As mysql documentation says, you should use alter user statement to change the password:
ALTER USER syntax is the preferred statement for account alterations, including assigning passwords. For example:
ALTER USER user IDENTIFIED BY 'auth_string'
PASSWORD() was deprecated in 5.7 and removed in version 8. Far more secure ways of handling passwords are available, and you should consider using one.
Updating the ACL system tables directly (or any system tables for that matter) is not a very sustainable practice.
Why would you need to execute
UPDATE mysql.user SET password = hash('clear-text-password') WHERE host = 'foo' and user = 'bar'
followed by a FLUSH PRIVILEGES (!)
when you can just do:
ALTER USER foo#bar IDENTIFIED BY 'clear-text-password' ?
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 want to revoke insert on a specific table form a user in mysql
and I try this code before:
use varian_db;
REVOKE INSERT ON 'gevhm_users' FROM 'varian_user';
but mysql returned this 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 ''gevhm_users' FROM 'varian_user'' at line 1
Please help.
You have to specify full path of database name and table name when granting or revoking privileges to/from such user. And also write user name in correct format. Your statement should like this:
REVOKE INSERT ON varian_db.gevhm_users FROM 'varian_user'#'user_ip_address';
FLUSH PRIVILEGES;
More information: MySQL Revoke Syntax
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;