0

On a CentOS server with LAMP I have a folder with 10-20 SQL dump files. Is there a way (single line query) by which I can import all of them?

I tried the following:

  1. logged in putty, navigated to to file with all SQL dump say (folder mysqlallfile)

    mysqlallfile contains: 1.sql.gz,2.sql.gz and so on

  2. I created sh file say bulkimport.sh

    #!/bin/sh
    for filename in *.gz; 
    do
        tempfile="${filename##*/}"
        database_name="${tempfile%%.*}"
        echo $database_name
        mysql -pPASS -u USER -e "CREATE DATABASE $database_name"
        gzcat $filename | mysql -pPASS -uUSER $database_name
    done
    
  3. I ran below command in the terminal:

    bash bulkimport.sh
    

    it returned error:

    bulkimport.sh: line 2: syntax error near unexpected token `$'\r''
    'ulkimport.sh: line 2: `for filename in *.gz;
    
0

1 Answer 1

2

You might have Windows line endings in the script file (or some other encoding error). Either save the file with Unix line endings in your editor in Windows and copy the script to the server again or use one of the myriad options to convert in Linux (e.g. dos2unix, recode, vim).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .