One: Problem description
These several times perform MongoDB initialization scripts and discover a problem:
When you upload a script from Windows to Linux, the error occurs when you execute it.
Such as:
Mongo-u root-p mongo123 Admin--port 8000 < initdata-bmis.sql > Initdata-bmis.log
There are many errors in the Initdata-bmis.log file:
Syntaxerror:unexpected token illegal But the direct copy paste script content executes on the command line without an error. or copy and paste the content into the new file under Linux, and execute without error.
And the script determines that there are no syntax errors.
Two: The cause of the error
formatting problems, Windows and Linux/unix are different for line breaks and blank lines.
III: Solutions
Method One:
While editing in notepad++ is encoded in UTF8 format, there is a place that requires transcoding, and windows and Linux/unix line breaks and blank lines are different, so the script edited under Windows can't run on Linux, After the notepad++ can be used in the transfer code.
Method Two:
Install Dos2unix on Linux and turn code
Yum Install-y Dos2unix
Dos2unix Initdata-bmis.sql
Do it again without an error:
Mongo-u root-p mongo123 Admin--port 8000 < initdata-bmis.sql > Initdata-bmis.log