So I try to lớn import sql tệp tin into rds (1G MEM, 1 CPU). The sql tệp tin is lượt thích 1.4G

mysql -h xxxx.rds.amazonaws.com -u user -ppass --max-allowed-packet=33554432 db < db.sql

It got stuck at:

ERROR 1227 (42000) at line 374: Access denied; you need (at least one of) the SUPER privilege(s) for this operation

The actual sql nội dung is:

/*!50003 CREATE*/ /*!50017 DEFINER=`another_user`@`1.2.3.4`*/ /*!50003 TRIGGER `change_log_BINS` BEFORE INSERT ON `change_log` FOR EACH ROW
IF (NEW.created_at IS NULL OR NEW.created_at = '00-00-00 00:00:00' OR NEW.created_at = '') THEN
        SET NEW.created_at = NOW();
END IF */;;

another_user is not existed in rds, sánh I do:

GRANT ALL PRIVILEGES ON db.* TO another_user@'localhost';

Still no luck.

xpt

22.8k45 gold badges148 silver badges241 bronze badges

asked May 17, 2017 at 4:35

Either remove the DEFINER=.. statement from your sqldump tệp tin, or replace the user values with CURRENT_USER.

The MySQL server provided by RDS does not allow a DEFINER syntax for another user (in my experience).

You can use a sed script to lớn remove them from the file:

sed 's/\sDEFINER=`[^`]*`@`[^`]*`//g' -i oldfile.sql

answered May 17, 2017 at 4:51

11

Remove the 3 lines below if they're there, or comment them out with -- :

At the start:

-- SET  SESSION.SQL_LOG_BIN= 0;
-- SET  GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';

At the end:

-- SET  SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;

Note that the comment characters are "dash dash space" including the space.

A better solution is to lớn stop these lines from being written to lớn the dump tệp tin at all by including the option --set-gtid-purged=OFF on your mysqldump command.

You can also force the import command to lớn import the table anyway despite this error (and any others) with the option --force or -f.

--force Continue even if an SQL error occurs

Ref https://dev.mysql.com/doc/refman/8.4/en/mysqlimport.html

answered Dec 23, 2019 at 11:38

4

Another useful trick is to lớn invoke mysqldump with the option --set-gtid-purged=OFF which does not write the following lines to lớn the output file:

SET  SESSION.SQL_LOG_BIN= 0;
SET  GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';
SET  SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;

not sure about the DEFINER one.

Dherik

19k15 gold badges125 silver badges173 bronze badges

answered Mar 10, 2020 at 16:19

3

When we create a new RDS DB instance, the mặc định master user is not the root user. But only gets certain privileges for that DB instance. This permission does not include SET permission. Now if your mặc định master user tries to lớn execute mysql SET commands, then you will face this error: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation

Solution 1

Comment out or remove these lines

SET @MYSQLDUMP_TEMP_LOG_BIN =  SESSION.SQL_LOG_BIN;
SET  SESSION.SQL_LOG_BIN= 1;
SET  GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';

Solution 2

You can also ignore the errors by using the -f option to lớn load the rest of the dump tệp tin.

mysql -f  -u  -h  -p < dumpfile.sql

answered Feb 26, 2021 at 7:28

2

Just a MacOS extra update for hjpotter92 answer.

To make sed recognize the pattern in MacOS, you'll have to lớn add a backslash before the = sign, lượt thích this:

sed -i old 's/\DEFINER\=`[^`]*`@`[^`]*`//g' tệp tin.sql

answered Nov 12, 2019 at 0:36

Problem: You're trying to lớn import data (using mysqldump file) to lớn your mysql database ,but it seems you don't have permission to lớn perform that operation.

Solution: Assuming you data is migrated ,seeded and updated in your mysql database, take snapshot using mysqldump and export it to lớn file

mysqldump -u [username] -p [databaseName] --set-gtid-purged=OFF > [filename].sql

From mysql documentation:

GTID - A global transaction identifier (GTID) is a unique identifier created and associated with each transaction committed on the server of origin (master). This identifier is unique not only to lớn the server on which it originated, but is unique across all servers in a given replication setup. There is a 1-to-1 mapping between all transactions and all GTIDs.

--set-gtid-purged=OFF SET GLOBAL.gtid_purged is not added to lớn the output, and SET SESSION.sql_log_bin=0 is not added to lớn the output. For a server where GTIDs are not in use, use this option or AUTO. Only use this option for a server where GTIDs are in use if you are sure that the required GTID phối is already present in gtid_purged on the target server and should not be changed, or if you plan to lớn identify and add any missing GTIDs manually.

Afterwards connect to lớn your mysql with user root ,give permissions , flush them ,and verify that your user privileges were updated correctly.

mysql -u root -p
UPDATE mysql.user SET Super_Priv='Y' WHERE user='johnDoe' AND host='%';
FLUSH PRIVILEGES;
mysql> SHOW GRANTS FOR 'johnDoe';
+------------------------------------------------------------------+
| Grants for johnDoe                                               |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `johnDoe`                                  |
| GRANT ALL PRIVILEGES ON `db1`.* TO `johnDoe`                     |
+------------------------------------------------------------------+

now reload the data and the operation should be permitted.

mysql -h [host] -u [user] -p[pass] [db_name] < [mysql_dump_name].sql

answered Mar 26, 2020 at 13:21

Full Solution

All the above solutions are fine. And here I'm gonna combine all the solutions sánh that it should work for all the situations.

  1. Fixed DEFINER

For Linux and Mac

sed -i old 's/\DEFINER\=`[^`]*`@`[^`]*`//g' tệp tin.sql

For Windows
download atom or notepad++, open your dump sql tệp tin with atom or notepad++, press Ctrl+F
search the word DEFINER, and remove the line DEFINER=admin@% (or may be little different for you) from everywhere and save the tệp tin.
As for example
before removing that line: CREATE DEFINER=admin@% PROCEDURE MyProcedure
After removing that line: CREATE PROCEDURE MyProcedure

  1. Remove the 3 lines Remove all these 3 lines from the dump tệp tin. You can use sed command or open the tệp tin in Atom editor and tìm kiếm for each line and then remove the line.
    Example: Open Dump2020.sql in Atom, Press ctrl+F, tìm kiếm SET SESSION.SQL_LOG_BIN= 0, remove that line.
SET  SESSION.SQL_LOG_BIN= 0;
SET  GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';
SET  SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN;
  1. There an issue with your generated file You might face some issue if your generated dump.sql tệp tin is not proper. But here, I'm not gonna explain how to lớn generate a dump tệp tin. But you can ask bủ (_)

answered Oct 2, 2020 at 8:54

Issue

Below statement or line your Dump tệp tin creating issue

DEFINER=username@`%

Simple Solution

The solution that you can workaround is to lớn remove all the entries from SQL dump tệp tin and import data from the GCP console.

 cát DUMP_FILE_NAME.sql |  sed -e 's/DEFINER=``@`%`//g' > NEW-CLEANED-DUMP.sql

above command will help to lớn remove all those lines from the dump tệp tin and create the new fresh dump tệp tin without Definer.

Try importing new file(NEW-CLEANED-DUMP.sql).

If you are on AWS RDS

You might see face issue, if your dump tệp tin is larger you can kiểm tra the first trăng tròn lines using

head -30 filename

once you can see output look for line and line number

SET  SESSION.SQL_LOG_BIN= 0;
SET  GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';
SET  SESSION.SQL_LOG_BIN = @MYSQLDUMP_TEMP_LOG_BIN; 

we will remove these lines by line numbers for example 17,18,24 line number

sed -e '24d;17d;18d' file-name.sql > removed-line-file-name.sql

answered Nov 14, 2019 at 9:39

For importing database tệp tin in .sql.gz format, remove definer and import using below command

zcat path_to_db_to_import.sql.gz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | mysql -u user -p new_db_name
  1. Earlier, export database in .sql.gz format using below command.

    mysqldump -u user -p old_db | gzip -9 > path_to_db_exported.sql.gz;

  2. Import that exported database and removing definer using below command,

    zcat path_to_db_exported.sql.gz | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | mysql -u user -p new_db

answered Jun 10, 2020 at 17:08

I commented all the lines start with SET in the *.sql tệp tin and it worked.

answered Dec 9, 2019 at 6:53

When you restore backup, Make sure to lớn try with the same username for the old one and the new one.

answered Sep 29, 2020 at 8:11

Simplest Soluction login: aws rds/ or other mysql server and assign required permissions, lập cập below commands(you can change username and host)

GRANT SESSION_VARIABLES_ADMIN ON *.* TO root@'%';
GRANT SYSTEM_VARIABLES_ADMIN ON *.* TO root@'%';

1

If it helps, when I tried to lớn restore a DB dump on my AWS MySQL RDS, I got this error:

ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER, 
SYSTEM_VARIABLES_ADMIN or SESSION_VARIABLES_ADMIN privilege(s) for this operation

I didn't have to lớn change the DEFINER or remove/comment out lines. I just did:

GRANT SESSION_VARIABLES_ADMIN ON *.* TO myuser@'myhost';
GRANT SYSTEM_VARIABLES_ADMIN ON *.* TO myuser@'myhost';

And I was able to lớn tự the restore.

answered Mar 3, 2021 at 11:27

None of the above solutions worked for bủ. I had to lớn tự the following:

  • Use the following flags with mysqldump:

    mysqldump --databases   --master-data=1 --single-transaction --order- 
    by-primary --foce -r all.sql -h -u -p
    
  • Remove the line that looks like:

    CHANGE MASTER TO MASTER_LOG_FILE='binlog.....
    
    • In my tệp tin, that was line #22, sánh I ran: sed -i '22d' all.sql
  • Import the data to lớn your RDS:

    mysql -h -u -p
    $ source all.sql
    

answered Mar 31, 2021 at 10:48

1

In my case (trying to lớn execute a SQL tệp tin into AWS RDS) the beginning of my SQL statement looked lượt thích this:

DROP VIEW IF EXISTS `something_view`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `something_view`...

All I had to lớn tự to lớn fix it was to lớn remove ALGORITHM=UNDEFINED DEFINER='root'@'%' SQL SECURITY DEFINER part of the above statement.

So the new statement looks lượt thích this:

CREATE VIEW 'something_view' ...

answered Jun 26, 2022 at 9:29

* Answer may only be applicable to lớn MacOS *

When trying to lớn import a .sql tệp tin into a docker container, I encountered the error message:

Access denied; you need (at least one of) the SUPER privilege(s) for this operation

Then while trying some of the other suggestions, I received the below error on my MacOS (osx)

sed: RE error: illegal byte sequence

Finally, the following command from this resource resolved my "Access Denied" issue.

LC_ALL=C sed -i old 's/\DEFINER\=`[^`]*`@`[^`]*`//g' fileName.sql

So I could import into the docker database with:

docker exec -i dockerContainerName mysql -uuser -ppassword table < importFile.sql

Hope this helps! :)

answered Apr 29, 2020 at 15:00

Issue in dump.

Please try to lớn get dump by following way:

mysqldump -h databasehost --user=databaseusername --password --single-transaction databasename  | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip > /tmp/database.sql.gz

Then, try to lớn import by following way:

zcat /tmp/database.sql.gz | mysql -h database_host -u username -p databasename

answered Mar 8, 2021 at 12:07

My Problem: I want to lớn dump the database from A provider to lớn restore a database on the database cluster on B provider with MySQL version 8 both via DBeaver.

Solution: I follow this step was worked. I hope this solution will help you.

  1. Backup database with additional option - Remove DEFINER

  1. Assign GRANT permission
GRANT ALL PRIVILEGES ON [database_name].* TO '[database_user]'@'[database_host]';
FLUSH PRIVILEGES;
  1. Restore database with sql dump tệp tin, you will found this error

Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation

  1. Go to lớn sql dump tệp tin, comment this line and save it
SET  GLOBAL.GTID_PURGED=/*!80000 '+'*/;

  1. Restore database to lớn destination server again

answered Jun 9, 2023 at 12:10

Some SET statements might require privileges,sánh you can try removing them:

sed -i '/^SET/d' dump.sql

answered Aug 25, 2023 at 9:04

Now you can grant SET_USER_ID to lớn the user which is running the import on a mysql RDS instance:
GRANT SET_USER_ID ON *.* TO 'import_user'@'%';

then you can run:
mysql -h xxxx.rds.amazonaws.com -u import_user -ppass db < db.sql

SET_USER_ID from mysql doc:

A user with this privilege can specify any trương mục as the DEFINER attribute of a view or stored program

answered Nov 27, 2023 at 17:19

In case someone is having a hard time trying to lớn lập cập Djando. I've found the inconvenience in seetings.py mysql connection

"OPTIONS": {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES', innodb_strict_mode=1"
}

Give the permissions for your MYSQL user, (i don't really know if it the correct solution but it works for bủ...)

GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;

Need to lớn phối "on" server parameter "log_bin_trust_function_creators" on server side. This one you can easily find on left side blade if it is azure maria db.

answered Oct 2, 2020 at 21:00