Using MySQL instance on AWS EMR cluster - mysql

I created an AWS EMR instance and logged in "Master" console via putty. I'm able to get in to MySQL command line on the console. I login as "hadoop#localhost"
mysql> SELECT user();
+------------------+
| user() |
+------------------+
| hadoop#localhost |
+------------------+
Now I want to create some users and databases for other projects. When I try to create a new user on MYSQL I get the below error.
How can I create user on EMR-MySQL instance, and give them permission ?
mysql> CREATE USER 'dbadmin'#'localhost' IDENTIFIED BY 'dbadmin';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
BTW when I login to MySQL console, it automatically logs me in as "hadoop#localhost", as that is the user I used to login to machine via putty.
Please advise. Thanks.

Hive uses MySQL for its metadata store on EMR. You will need to stop the MySQL service, restart in safe mode and do a standard root password recovery. This will give you root access. However, STOP and don't do this. Create your MySQL database somewhere else.

you could do sudo mysql and it should work.
sudo mysql
CREATE USER 'dbadmin'#'localhost' IDENTIFIED BY 'dbadmin';
Query OK, 0 rows affected (0.00 sec)

Related

Importing mysql5.8 dump into mariadb 10.5 does not let me use already created users

I've a very fresh installation of mariadb-server-10.5 (1:10.5.15-0+deb11u1) on a freshly installed debian 11.1 .
On the old machine with mysql-server (5.5.9999+default) and debian 9.6 I created a dump like this:
mysqldump -u root -pSOMEPW --all-databases > all_databases.dump
and I loaded this dump on the new server:
source /path/to/all_databases.dump
. The source took a while, did not result any error, however it beeped once at the end (no visible error or warning message).
Checking the mysql.user table it has only 3 entries for root, mysql and mariadb.sys , so I tried to create users (which were existing and used on the old machine) with this command:
create user 'testuser'#'localhost' identified by 'pw';
but it result this error:
ERROR 1396 (HY000): Operation CREATE USER failed for 'testuser'#'localhost'
.
With a short script checking all the tables of the mysql db the 'testuser' appears in 3 different tables, but as a User only in the db table twice like this:
| Host | Db | User | Select_priv
| localhost | somedb | testuser | Y
| localhost | somedbp2 | testuser | Y
.
I think that might cause create user to fail.
How could I fix this issue without losing the information in the db table?
Thanks.
In general you need to run mysql_upgrade whenever you switch to a more recent MySQL or MariaDB release, or after importing a backup taken from an older major version.
This is especially true for MariaDB 10.4 and later when importing from MySQL or from MariaDB 10.3 or earlier, as the internal privilege tables changed substantially with 10.4.
mysql.user table was replaced by mysql.global_priv in 10.4, allowing for more fine grained authentication control, e.g. supporting multiple authentication plugins for a single user.
So now mysql.user is just a VIEW presenting information from mysql.global_priv in a backwards compatible way. Simple information like user and host name can still be modified via that view directly as it is an updateable view, but this does not work for the more complex columns.
And commands like CREATE USER now directly operate on the mysql.global_priv table anyway, the errors you are getting are due to that table not being present in your imported dump.
The good news is: mysql_upgrade will take care of the necessary conversion, and after that CREATE USER should work again.
See also: https://mariadb.com/kb/en/mysql_upgrade/
See also: https://mariadb.com/kb/en/mysqlglobal_priv-table/

Can't recreate mysql user

I am using mysql-server 5.5.41-0+wheezy1 on Debian 3.2.54-2 x86_64
I have problems (not related to mysql) on some on my web app that uses mysql table so I am doing a re-install of the app
I started with aptitude remove packagename to remove my app and mysql-server, but it seems that it did not remove/delete the currently used mysql databases
When I reinstall mysql-server the previous database still used. I drop the previous user to create a new one using the command drop user olduser and also I drop the old database drop database olddb
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
Now when I recreate the database with new name, it is a sucess, but if I recreate the same old user create user 'olduser'#'localhost' identified by 'somesecret'; it will always say ERROR 1396 (HY000): Operation CREATE USER failed for 'olduser'#'localhost' Creating a different user is a success, but this problem of recreating the same old user is bugging me. Is there something wrong or something I missed?
I have tried flush privileges
Well it's kinda hard to debug this without having any access to the database, this error is common with MySQL, but normally a FLUSH PRIVILEGES fix it. Anyway, if really the user is dropped you can bypass it that way :
CREATE USER 'anyuser'#'localhost' IDENTIFIED BY 'test123';
UPDATE mysql.user SET USER='olduser' WHERE USER='anyuser';
Note that to completly remove an user, you must delete all datas associated to it in these tables : columns_priv, db, procs_priv, tables_priv. Then finally execute flush privileges.
From the doc :
DROP USER does not automatically drop or invalidate databases or
objects within them that the old user created. This includes stored
programs or views for which the DEFINER attribute names the dropped
user. Attempts to access such objects may produce an error if they
execute in definer security context. (For information about security
context, see Section 18.5, “Access Control for Stored Programs and
Views”.)

1148 - The used command is not allowed with this MySQL version [duplicate]

I have a PHP script that calls MySQL's LOAD DATA INFILE to load data from CSV files. However, on production server, I ended up with the following error:
Access denied for user ... (using password: yes)
As a quick workaround, I changed the command to LOAD DATA LOCAL INFILE which worked. However, the same command failed on client's server with this message:
The used command is not allowed with this MySQL version
I assume this has something to do with the server variable: local_infile = off as described here.
Please suggest a workaround that does not involve changing server settings. Note that phpMyAdmin utility installed on the same server appears to accept CSV files though I am not sure it it uses LOAD DATA (LOCAL) INFILE.
Ran into the same issue as root and threw me for a moment
could be an issue with your server settings set with compile
to test login to console with the same user and try your load data command
if you get the same error, try closing console and running
mysql -u USER -p --local-infile=1 DATABASE
now try running load data command again
if it works then you're going to need to restart mysqld with command line option or re-install with configuration option
references (references are for 5.0 but worked for me with 5.5):
http://dev.mysql.com/doc/refman/5.0/en/load-data-local.html
http://dev.mysql.com/doc/refman/5.0/en/mysql-command-options.html#option_mysql_local-infile
I found that I need to connect to database like this:
$dbh=mysql_connect($server,$dbuser,$dbpass,false,128);
Passing 128 in the flags parameter is the key.
See http://www.php.net/manual/en/mysql.constants.php#mysql.client-flags to read more about the flags.
take a look to this permission list, you can add them separately, IE. you can insert but not update, or you can delete but not select, etc...
ALL [PRIVILEGES] Grant all privileges at specified access level except GRANT OPTION
ALTER Enable use of ALTER TABLE
ALTER ROUTINE Enable stored routines to be altered or dropped
CREATE Enable database and table creation
CREATE ROUTINE Enable stored routine creation
CREATE TEMPORARY TABLES Enable use of CREATE TEMPORARY TABLE
CREATE USER Enable use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES
CREATE VIEW Enable views to be created or altered
DELETE Enable use of DELETE
DROP Enable databases, tables, and views to be dropped
EVENT Enable use of events for the Event Scheduler
EXECUTE Enable the user to execute stored routines
FILE Enable the user to cause the server to read or write files
GRANT OPTION Enable privileges to be granted to or removed from other accounts
INDEX Enable indexes to be created or dropped
INSERT Enable use of INSERT
LOCK TABLES Enable use of LOCK TABLES on tables for which you have the SELECT privilege
PROCESS Enable the user to see all processes with SHOW PROCESSLIST
REFERENCES Not implemented
RELOAD Enable use of FLUSH operations
REPLICATION CLIENT Enable the user to ask where master or slave servers are
REPLICATION SLAVE Enable replication slaves to read binary log events from the master
SELECT Enable use of SELECT
SHOW DATABASES Enable SHOW DATABASES to show all databases
SHOW VIEW Enable use of SHOW CREATE VIEW
SHUTDOWN Enable use of mysqladmin shutdown
SUPER Enable use of other administrative operations such as CHANGE MASTER TO, KILL, PURGE BINARY LOGS, SET GLOBAL, and mysqladmin debug command
TRIGGER Enable trigger operations
UPDATE Enable use of UPDATE
USAGE Synonym for “no privileges”
I think you have permision to select, delete, insert, update, but no to do other stuff,
use this command:
SHOW GRANTS
he will show you what you are able to to, in my case.
jcho360> show grants;
+-------------------------------------------------------+
| Grants for jbolivar#localhost |
+-------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'jbolivar'#'localhost' |
+-------------------------------------------------------+
1 row in set (0.00 sec)

MySQL Grant All Commands?

I am trying to install daisy and I am following their install guide and running these commands as localhost root:
CREATE DATABASE daisyrepository CHARACTER SET 'utf8';
GRANT ALL ON daisyrepository.* TO daisy#'%' IDENTIFIED BY 'daisy';
GRANT ALL ON daisyrepository.* TO daisy#localhost IDENTIFIED BY 'daisy';
CREATE DATABASE activemq CHARACTER SET 'utf8';
GRANT ALL ON activemq.* TO activemq#'%' IDENTIFIED BY 'activemq';
GRANT ALL ON activemq.* TO activemq#localhost IDENTIFIED BY 'activemq';
The databases are created successfully but each of my GRANT ALL commands completes but it shows 0 records updated:
mysql> GRANT ALL ON *.* TO daisy#localhost IDENTIFIED BY 'daisy';
Query OK, 0 rows affected (0.00 sec)
I am running into a problem in the future of the install guide that seems to be related to this section. What am I doing wrong?
Additional info in the install guide about this section if it helps:
Now create the necessary databases, users and access rights by entering (or copy-paste) the commands below in the mysql client. What follows behind the IDENTIFIED BY is the password for the user, which you can change if you wish. The daisy#localhost entries are necessary because otherwise the default access rights for anonymous users #localhost will take precedence. If you'll run MySQL on the same machine as the Daisy Repository Server, you only need the #localhost entries.
What am I doing wrong?
Everything is fine. The query haven't returned any rows and didn't affect any rows (only explicit DML queries affect rows) - so you get 0

ERROR 1396 (HY000): Operation CREATE USER failed for 'jack'#'localhost'

I seem to be unable to re-create a simple user I've deleted, even as root in MySQL.
My case: user 'jack' existed before, but I deleted it from mysql.user in order to recreate it. I see no vestiges of this in that table. If I execute this command for some other, random username, say 'jimmy', it works fine (just as it originally did for 'jack').
What have I done to corrupt user 'jack' and how can I undo that corruption in order to re-create 'jack' as a valid user for this installation of MySQL?
See example below. (Of course, originally, there was much time between the creation of 'jack' and his removal.)
mysql> CREATE USER 'jack'#'localhost' IDENTIFIED BY 'test123';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from user;
+------------------+-----------------+
| user | host |
+------------------+-----------------+
| root | 127.0.0.1 |
| debian-sys-maint | localhost |
| jack | localhost |
| root | localhost |
| root | russ-elite-book |
+------------------+-----------------+
5 rows in set (0.00 sec)
mysql> delete from user where user = 'jack';
Query OK, 1 row affected (0.00 sec)
mysql> select user,host from user;
+------------------+-----------------+
| user | host |
+------------------+-----------------+
| root | 127.0.0.1 |
| debian-sys-maint | localhost |
| root | localhost |
| root | russ-elite-book |
+------------------+-----------------+
4 rows in set (0.00 sec)
mysql> CREATE USER 'jack'#'localhost' IDENTIFIED BY 'test123';
ERROR 1396 (HY000): Operation CREATE USER failed for 'jack'#'localhost'
mysql> CREATE USER 'jimmy'#'localhost' IDENTIFIED BY 'test123';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from user;
+------------------+-----------------+
| user | host |
+------------------+-----------------+
| root | 127.0.0.1 |
| debian-sys-maint | localhost |
| jimmy | localhost |
| root | localhost |
| root | russ-elite-book |
+------------------+-----------------+
5 rows in set (0.00 sec)
yes this bug is there. However, I found a small workaround.
Assume the user is there, so drop the user
After deleting the user, there is need to flush the mysql privileges
Now create the user.
That should solve it. Assuming we want to create the user admin # localhost, these would be the commands:
drop user admin#localhost;
flush privileges;
create user admin#localhost identified by 'admins_password'
Try doing a FLUSH PRIVILEGES;. This MySQL bug post on that error code appears to report some success in a case similar to yours after flushing privs.
This bug has been sitting on bugs.mysql.com since 2007 and this thread is mainly just a parroting of all those wrong answers even up to a year ago.
According to the MySQL documentation, commands like CREATE USER, GRANT, REVOKE, and DROP USER do not require a subsequent FLUSH PRIVILEGES command. It's quite clear why, if one reads the docs. It's because altering the MySQL tables directly does not reload the info into memory; yet the plethora of solutions to this bug claim that FLUSH PRIVILEGES is the answer.
This also may not even be a bug. It is a documentation conspiracy - docs vary in one critical place from version to version.
13.7.1.2. DROP USER Syntax
...
DROP USER user [, user] ...
...
DROP USER 'jeffrey'#'localhost';
If you specify only the user name part of the account name, a host name part of '%' is used.
DROP USER as present in MySQL 5.0.0 removes only accounts that have no privileges. In MySQL 5.0.2, it was modified to remove account privileges as well. This means that the procedure for removing an account depends on your version of MySQL.
As of MySQL 5.0.2, you can remove an account and its privileges as follows:
DROP USER user;
The statement removes privilege rows for the account from all grant tables.
The only time I get this error is when I do DROP USER user; like the doc suggests, but MySQL does not treat the '%' as a wildcard in a way that would drop all users at all hosts. It's not so wild after all. Or, it may be that it sometimes works when it deletes the localhost user and then tries to delete the one at %.
It's clear to me that when it tries to delete the user at %, it issues an error message and quits. Subsequent CREATE USER at localhost will fail because the localhost user was never deleted. There seems to be no need to waste time digging in the grant tables looking for ghosts as one poster suggested.
I see 7 votes for:
DROP USER 'jack#localhost'; // completely delete the account
Which is interpreted as DROP USER 'jack#localhost'#'%'; # wrong
There actually seems to be a real bug that generates the same error message, but it has to do with the first created user (after a new mysql server install) being dropped. Whether that bug has been fixed, I don't know; but I don't recall that happening lately and I'm up to ver 5.5.27 at this time.
If you use a DELETE statement on the mysql.user table in an attempt to remove a user, then attempt to re-establish the user with CREATE USER, you will get a 1396 error. Get rid of this error by running DROP USER 'username'#'host';
DELETE
FROM mysql.user
WHERE user = 'jack';
(You will get 1396 errors if you attempt to re-create jack)
CREATE USER 'jack'#'localhost' IDENTIFIED BY PASSWORD '*Fi47ytFF3CD5B14E7EjkjkkC1D3F8086A5C0-krn';
(Get out of this situation by running DROP USER)
DROP USER 'jack'#'localhost';
(I suppose FLUSH PRIVILEGES can't hurt, but definitely drop the user first.)
You shouldn't be manually deleting users that way. MySQL has REVOKE syntax for removing privileges and DROP USER for deleting them:
REVOKE priv1,priv2,priv3,etc... FROM 'jack#localhost'; // remove certain privileges
DROP USER 'jack#localhost'; // completely delete the account
Best to use the tools provided rather than mucking around in the background.
Drop the user, flush the privileges; then, create the user. It does work!
try delete from mysql.db where user = 'jack' and then create a user
Check if is
'user'#'%'
or
'user'#'localhost'
In MySQL 5.6 using Drop user userid; does not work. Use: Drop user 'userid'#'localhost'; and/or Drop user 'userid'#'%';. In this way I was able to drop the user and recreate it.
If you want to delete a user with sql, you need to delete the related data in these tables: columns_priv, db, procs_priv, tables_priv. Then execute flush privileges;
two method
one :
setp 1: drop user 'jack'#'localhost';
setp 2: create user 'jack'#localhost identified by 'ddd';
two:
setp 1: delete from user where user='jack'and host='localhost';
setp 2: flush privileges;
setp 3: create user 'jack'#'localhost' identified by 'ddd';
I had the same error. But command "FLUSH PRIVILEGES;" didn't help.
I did like that:
CREATE USER 'jimmy'#'localhost' IDENTIFIED BY 'test123';
UPDATE mysql.user SET USER='jack' WHERE USER='jimmy';
BUG of MySql Solved: Error Code-1396
Whenever you had try to run query which create a User as Shown Below.
MySql> CREATE USER 'springstudent'#'localhost' IDENTIFIED BY 'springstudent';
GRANT ALL PRIVILEGES ON * . * TO 'springstudent'#'localhost';
But when you try to run query which create user within all previleges,
Due to bug it create gives previleges without showing user
Because of this Problem we need to use this script for flush priviledges
MySql> drop user 'springstudent'#'localhost';
flush privileges;
create user admin#localhost identified by 'admins_password'
After deleting the user, there is need to flush the mysql privileges
Then Create User again
Gotchaaa.... Solved....
A simple work around on this issue. As "delete" command only removes the user record in "user" table of "mysql" database, we could add it back and then drop the user completely. Then you could create user with same name.
Step 1. find the record format of user table in mysql database
use mysql;
select * from user;
Step 2. According to the columns showed in step1, create a dummy record with the user name. Insert it into the table, for example, be reminded to replace the "username" with your username.
Insert into user value ('%','username','N','N','N','N','N',
'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N',
'N','N','N','N','N','N','N','N','N','','','','','0','0','0',
'0','mysql_native_password',
'*52C5E3AC6BC5E2E0BFF86978BF62A1481AC79D58','N',
'2016-12-10 23:59:12',null,'N');
Note: sometimes you may encounter issues in inserting, just change the data to make it work.
Step 3. Drop the user.
drop user username;
Now you are able to create user with same name.
Funnily enough the MySQL workbench solved it for me. In the Administration tab -> Users and Privileges, the user was listed with an error. Using the delete option solved the problem.
Seems you need to create user for your database and grant privileges for created user
--> create user for Data base
CREATE USER <'username'>#'%'IDENTIFIED BY <'password'>;
ex - CREATE USER 'root'#'%'IDENTIFIED BY 'root';
--> Grant Privileges
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON <db name>.* TO '<username>'#'%';
ex- GRANT ALL PRIVILEGES ON mydb.* TO 'root'#'%';
This post MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES) is useful. Sometimes, there is an anonymous user ''#'localhost' or ''#'127.0.0.1'. So, to solve the problem,
first drop the user whose 'create user' failed.
Create new user.
Grant required privileges to the new user.
Flush privileges.
I faced this issue today, and I resolved it by doing the following steps:
1) manually inserting that troubling user providing value of mandatory fields into mysql.user
mysql> insert into user(Host, User, Password, ssl_type)
values ('localhost', 'jack', 'jack', 'ANY');
2)
mysql> select * from user where User = 'jack';
1 row in set (0.00 sec)
3) A.
mysql> drop user jack;
Query OK, 0 rows affected (0.00 sec)
B. mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
C. mysql> create user 'jack' identified by 'jack';
Query OK, 0 rows affected (0.00 sec)
D. mysql> select Host, User, Password, ssl_type from user where User = 'jack';
+-----------+-----------+-------------------------------------------+----------+
| Host | User | Password | ssl_type |
+-----------+-----------+-------------------------------------------+----------+
| localhost | jack | jack | ANY |
| % | jack | *45BB7035F11303D8F09B2877A00D2510DCE4D758 | |
+-----------+-----------+-------------------------------------------+----------+
2 rows in set (0.00 sec)
4) A.
mysql> delete from user
where User = 'nyse_user' and
Host = 'localhost' and
Password ='nyse';
Query OK, 1 row affected (0.00 sec)
B.
mysql> select Host, User, Password, ssl_type from user where User = 'jack';
+------+-----------+-------------------------------------------+----------+
| Host | User | Password | ssl_type |
+------+-----------+-------------------------------------------+----------+
| % | jack | *45BB7035F11303D8F09B2877A00D2510DCE4D758 | |
+------+-----------+-------------------------------------------+----------+
1 row in set (0.00 sec)
Hope this helps.
I had the same problem as OP, and the accepted answer did not work for me. In the comments of the accepted answer, #Rathish posted a solution which worked for me, I wanted to call attention to it.
Here's the link:
https://www.rathishkumar.in/2018/10/Error-1396-HY000-Operation-CREATE-DROP-USER-failed-for-user-host.html
Rathish's solution is to revoke access for all users:
REVOKE ALL ON *.* FROM 'user'#'host';
DROP USER 'user'#'host';
FLUSH PRIVILEGES;
And he also helpfully points out that you can query the following tables by selecting "user" and "host" to determine whether you have a vestigial user left-over from a previous operation:
mysql.user: User accounts, global privileges, and other non-privilege columns
mysql.db: Database-level privileges
mysql.tables_priv: Table-level privileges
mysql.columns_priv: Column-level privileges
mysql.procs_priv: Stored procedure and function privileges
mysql.proxies_priv: Proxy-user privilege
Thank you!
replace localhost by 127.0.0.1
it works for me
Step 1) Open MySQL Command Line Client.
Step 2) Check all the users using : select user, host from mysql.user;
Step 3) Delete the user using : drop user username#localhost;
Step 4) Again create user using MySQL GUI.
Step 5) Problem is solved now.
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
I know this is old, but since it is the first result in Google I figured I should add my solution. In my case dropping the user worked fine, but recreating the user gave me a "ERROR 2013 (HY000): Lost connection to MySQL server during query" and "ERROR 2006 (HY000): MySQL server has gone away." I tried the flush privileges -> drop user solution, but still had the same error.
In my case the error was due to a mysql upgrade from 5.1 -> 5.6. Viewing the error logs, I noticed that it said to run mysql_upgrade. Did that and my create user statement worked fine!
I recently got this error.
What worked for me is checking in the mysql workbench 'Users and Privileges' and realizing user still existed.
After deleting it from there, I was able to recreate the user.
mysql> DELETE FROM mysql.db WHERE user = 'jack'
Restart the server:
# mysql.server restart
Then do your CREATE USER command.
My experience with this error resulted from me doing explicit delete from mysql.user, but not from mysql.db
Turns out if the user name in the create exists is in either user or db, you get this error. Solve by doing
delete from mysql.user where User == 'user#bar';
delete from mysql.db where User == 'user#bar';
Just delete the user related data from mysql.db(maybe from other tables too), then recreate both.
I had also faced the same issue, after few searches, I found a solution that worked for me.I hope it will help you.
As you have already created users, now try to do a FLUSH PRIVILEGES on your Mysql console.
This issue is already in MySql bug post.You can also check this one.Now after flushing, you can create a new user.
follow below Steps:
Step-1: Open terminal Ctrl+Alt+T
Step-2: mysql -u root -p , it will ask for your MySQL password.
Now you can able to see Mysql console.
Step-3: CREATE USER 'username'#'host' IDENTIFIED by 'PASSWORD';
Instead of username you can put username you want. If you are running Mysql on your local machine, then type "localhost" instead of the host, otherwise give your server name you want to access.
Ex: CREATE USER smruti#localhost IDENTIFIED by 'hello';
Now new user is created. If you want to give all access then type
GRANT ALL PRIVILEGES ON * . * TO 'newuser'#'localhost';
Now you can quit the MySQL by typing \q.Now once again login through
mysql -u newusername -p , then press Enter. You can see everything.
Hope this helps.