-1

I'm new to Cygwin but can't find anything online to do what I need.

I downloaded this script (MySQL to Sqlite) and was able to successfully run it within the Cygwin64 Terminal with the below command and get a converted database

./mysql2sqlite.sh -h 127.0.0.1 -u root -pMySecretPassword databaseName | sqlite3 database.sqlite

What I'm hoping to do is call this script with the parameters from a Windows Command Line or within a .Net application.

This does NOT work but would expect it to

C:\cygwin64\bin\mintty.exe -e '/cygdrive/c/cygwin64/mysql2sqlite.sh' -h 127.0.0.1 -u root -pMySecretPassword databaseName | sqlite3 database.sqlite

What is the correct way to execute a script in mintty and provide the parameters the script needs as well?

0

I got this working the way I want.

This script does in fact successfully convert a MySQL database to SQLite database, but only if the MySQL database is very basic. There are features in MySQL that SQLite doesn't support. Like Triggers, etc.

My whole problem was getting an automated way within Windows to execute this script, passing in the parameters the script needed for mysqldump to connect to MySQL and also for SQLite to get the data and import into a new SQLite database. Previous attempts has the mysqldump output being printed to the console and not to the SQLite3.exe

Solution:

1) Save the mysql2sqlite.sh script into "C:\cygwin64\bin"

2) Create a batch file (With below contents) and save in "C:\cygwin64"

@echo off

SET script='/bin/mysql2sqlite.sh'

SET host=%1%

SET user=%2%

SET pass=%3%

SET database=%4%

SET params=%script% -h %host% -u %user% -p%pass% %database%

C: chdir C:\cygwin64\bin

bash --login -i %params%|sqlite3 /cygdrive/c/cygwin64/%database%.db3

3) Call this batch file anywhere in Windows

C:\cygwin64\convert.bat mysql_host mysql_user mysql_pass mysql_db

You could expand on the batch file to take a parameter for the destination SQLite database save directory.

-1

The pipe (|) must be in the shell command. The way it's written in your example, the pipe character and what follows are arguments to the .exe binary.

So try something like this:

C:\cygwin\bin\mintty.exe -h always -e /bin/sh -c \
'/cygdrive/c/cygwin64/mysql2sqlite.sh| /bin/sqlite3 database.sqlite'

Make sure the pipe appears in the command-string that comes after -c.


If the resulting database file is empty, it means that the script incorrectly converted the output from mysqldump. This can be verified like this:

echo 'create table tbl1(one varchar(10), two smallint); ' | \
sqlite3 moo.db || echo  script failed

Which means print some SQL commands, feed them to sqlite or (||) echo some message if sqlite exits with an error.

I tried running the conversion script on a wordpress database. The results were:

./mysql2sqlite.sh -h zzz.domeneshop.no -u xxx  -pyyy dbname |\
sqlite dbname.db 2> sqlite.errors || echo script failed
memory
script failed

Which suggests that the AWK program is flawed. This is true because the error log did indeed have contents;

$ grep Error sqlite.errors
Error: near line 29: near "Y": syntax error
Error: near line 175: no such table: wp_options
Error: near line 176: no such table: wp_options
Error: near line 177: no such table: wp_options
Error: near line 178: no such table: wp_options
Error: near line 179: near "_transient_timeout_feed_mod_b9388c83948825c1edaef0d856b7b109": syntax error
Error: near line 191: no such table: wp_options
Error: near line 192: no such table: wp_options
(...)

So the verdict is that the obscure script is indeed flawed. The sqlite binary is unable to parse the output of the mysgl2sqlite.sh script.

  • If it's not too much trouble, could you modify your answer to accept the arguments for that script so I can see exactly what you mean with the pipes? – ScottN Sep 17 '13 at 2:17
  • C:\cygwin\bin\mintty.exe -h always -e /bin/sh -c '/cygdrive/c/cygwin64/mysql2sqlite.sh| /bin/sqlite3 database.sqlite' – Ярослав Рахматуллин Sep 17 '13 at 5:12
  • Thanks for your reply. If I run this command: mintty -h always -e /bin/sh -c '/cygdrive/c/cygwin64/convert.sh -h 127.0.0.1 -u root -pMyPassword dbName| sqlite3 db.db3' it executes but the SQL commands that are meant for sqlite3 are posted to the console instead and not to sqlite3. If I run this command mintty -h always -e /bin/sh -c '/cygdrive/c/cygwin64/convert.sh -h 127.0.0.1 -u root -pMyPassword dbName| /bin/sqlite3 db.db3' mintty returns to Win command line error 'The system cannot find the path specified.' Any ideas? – ScottN Sep 17 '13 at 17:01
  • I have many ideas. If your question about how to run a shell script with a pipe in it from a mintty terminal has been answered, mark any satisfactory answers as accepted and ask new questions relevant or irrelevant to this issue. I.E If you don't know what to do with the convert scripts' output, ask a new question. Don't ask follow-up questions in comments. Besides, how is anyone supposed to know what your script wants? Be reasonable. – Ярослав Рахматуллин Sep 18 '13 at 0:50
  • My original question was based around getting a solution to execute the linked script, you gave an answer that, yes, did execute a script but didn't reference anything related to my original question. If you would of wrote your answer in the way that it actually used my script and the parameters it needed, it would've been more helpful. As you can see from my question, I'm new to cygwin and am willing to learn if someone would take the time to teach. – ScottN Sep 18 '13 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.