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

后端 未结 12 993
余生分开走
余生分开走 2020-12-12 14:26

So I try to import sql file into rds (1G MEM, 1 CPU). The sql file is like 1.4G

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

相关标签:
12条回答
  • 2020-12-12 14:33

    I commented all the lines start with SET in the *.sql file and it worked.

    0 讨论(0)
  • 2020-12-12 14:39

    Statement

    DEFINER=username@`%

    is an issue in your backup dump.

    The solution that you can work around is to remove all the entry from sql dump file and import data from GCP console.

    cat DUMP_FILE_NAME.sql | sed -e 's/DEFINER=<username>@%//g' > NEW-CLEANED-DUMP.sql

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

    0 讨论(0)
  • 2020-12-12 14:41

    Full Solution

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

    1. Fixed DEFINER

    For Linux and Mac

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

    For Windows
    download atom or notepad++, open your dump sql file 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 file.
    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 file. You can use sed command or open the file in Atom editor and search for each line and then remove the line.
      Example: Open Dump2020.sql in Atom, Press ctrl+F, search 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 file is not proper. But here, I'm not gonna explain how to generate a dump file. But you can ask me (_)
    0 讨论(0)
  • 2020-12-12 14:43

    * Answer may only be applicable to MacOS *

    When trying to import a .sql file 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! :)

    0 讨论(0)
  • 2020-12-12 14:49

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

    0 讨论(0)
  • 2020-12-12 14:50

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

    Solution: Assuming you data is migrated ,seeded and updated in your mysql database, take snapshot using mysqldump and export it to 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 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 the output, and SET @@SESSION.sql_log_bin=0 is not added to 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 set is already present in gtid_purged on the target server and should not be changed, or if you plan to identify and add any missing GTIDs manually.

    Afterwards connect to 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
    
    0 讨论(0)
提交回复
热议问题