How do I load a sql.gz file to my database? (importing)

后端 未结 7 1146
-上瘾入骨i
-上瘾入骨i 2021-02-05 01:34

is this right?

mysql -uroot -ppassword mydb < myfile.sql.gz
相关标签:
7条回答
  • 2021-02-05 02:17

    Straight and clear:

    gunzip -c myfile.sql.gz | mysql -uroot -ppassword mydb

    -c option for gunzip writes to stdout, keeps original files

    NOTE: You shouldn't put the password directly in the command. It's better to provide just -p and than enter the password interactively.

    0 讨论(0)
  • 2021-02-05 02:26
    • You must not use the password directly in the terminal, use without it like follows
    zcat YOUR_FILE.sql.gz | mysql -u YOUR_DB_USERNAME -p YOUR_DATABASE_NAME
    
    • Hit enter and when terminal asked for your password, type your password and hope everything will work fine.
    0 讨论(0)
  • 2021-02-05 02:28

    Use the following command:

    gunzip < databasefile.sql.gz | mysql -u root -p dbname
    
    0 讨论(0)
  • 2021-02-05 02:28

    For Generating dbName.sql.gz

    mysqldump -u <YOUR USERNAME> -p<YOUR PASSWORD> <YOUR DBNAME> | gzip > ~/mysqlBackup/dbName_`date +%Y%m%d%H%M`.sql.gz
    

    For Loading dbName.sql.gz

    zcat ~/mysqlBackup/<.SQL.GZ file> | mysql -u <YOUR USERNAME> -p<YOUR PASSWORD> <DATABASE NAME IN WHICH YOU WANT TO LOAD>
    
    0 讨论(0)
  • 2021-02-05 02:35

    tar -xzf myfile.tar.gz

    Check the extracted sql files using: ls

    mysql -u root -p password database < myfile.sql

    0 讨论(0)
  • 2021-02-05 02:37

    You have to follow below steps:

    • First check Mysql service should be running.

    • Then if you have compressed file, decompress it first.

    • Then you will find .sql file after decompressing.
    • Then find import data in left corner in Mysql.
    • Select option import from self-contained file and select your .sql file and specify a new schema name.
    • Then click on import data.
    • After importing you will see your new schema in available schema list.
    0 讨论(0)
提交回复
热议问题