Skip to content
Advertisement

How to call this shell script to convert mysqldump to SQLite compatible syntax

I need to autonomously convert mysqldump files (.sql file) to SQLite compatible .sql files. I found this script on github which is supposed to be able to do this. If I had an unmodified .sql file from MySQL called test.sql whose database’s name was test and the script mysql2sqlite.sh in a directory, how would I call it.

The script says in the comments how to call it. I believe my scenario matches the first one titled usage because I already have the mysqldump file.

JavaScript

I read in the comments on the github page to change the scripts permissions with chmod +x mysql2sqlite.sh so navigated to the directory with the sql and the script and did that. Then I tried:

pi@raspberrypi ~ $ ./mysql2sqlite.sh test.sql test | sqlite3 database.sqlite

It failed with the error: -bash: ./mysql2sqlite.sh: /bin/sh^M: bad interpreter: No such file or directory

I then read online that to call an .sh file you type sh myShellFile.sh

So I tried sh mysql2sqlite.sh test.sql test | sqlite3 database.sqlite and got back:

JavaScript

It appears that its trying to connect to a server rather than reading the mysqldump file that I provided. What is the proper way to call this script. I have some experience with Linux and no experience with unix shells.

It may be of some use to read the background of my problem

EDIT: After editing the first line of the script running it again produces the error Error: near line 4: near "Insert": syntax error

Here is the sqldump I’m trying to process:

JavaScript

Advertisement

Answer

You’re misinterpreting the comments in the script. The script is expecting mysql dump options followed by the dbname (not a dump file). If you look at the first line of code you will see how it works.

JavaScript

The script is expecting the output MySQL data to be using the parameters it also passes, so the best method is probably to use the script as intended.

JavaScript

If you can only do this from an existing dump file, then you could change that first mysqldump line in the code to this

JavaScript

Then you could do this

JavaScript

Keep in mind that this script is not a silver bullet, you may run into other incompatibility issues. You may be able to resolve them by directly editing the dump file itself. Good luck.

http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

Edit: As I originally stated, this script is not a magic bullet and you may have to edit your dump to make it work (best compatibility coming from using it’s built in dump function) I’ve edited your script to what you see below and it should work.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement