Incorrect syntax when import sql file from MySQL to MS SQL via SQLCMD - mysql

I have large .sql files exported from MySQL, and try to import them to MS SQL(localDB) via
SQLCMD. But when I type in the following into Command-prompt:
sqlcmd.exe -S (localdb)\MSSQLLocaldb -i
C:\Users\Administrator\Desktop\1\SQLQuery4.sql
I got the following error message:
Incorrect syntax near 'tblo'
I checked my .sql file, it seems SQLCMD can't understand double quotes
e.g.
INSERT INTO "tblo" VALUES (2,'DTT','10000286','Dp','y',2,38,'2010-02-22
11:03:51','2010-02-22 11:03:51');
However, it's fine with SSMS
Any idea to solve this problem?

I found a solution by myself:
I can add --skip-quote-names flag when I dump data from MySQL
e.g.
mysqldump.exe -hlocalhost -uUserName -pPassword --compatible=mssql --no-create-info --skip-quote-names --skip-add-locks DataBase tblo > D:\Test\dump.sql
Result in dump.sql will be like:
INSERT INTO tblo VALUES (2,'DTT','10000286','Dp','y',2,38,'2010-02-22 11:03:51','2010-02-22 11:03:51');
So I can use this .sql to directly import data into MS SQL server via SQLCMD
sqlcmd -S (localdb)\MSSQLLocaldb -i D:\Test\dump.sql

Related

Mysql database queries not showing in command line when importing using command line phpmyadmin

Friend i am trying to import sql database using command line it is importing fine with this command but not showing progress in command line
C:\xampp\mysql\bin
mysql -u username -p databasename < dump.sql
Its normal for there not to be any output when importing data in this way using mysql.
You'll get a prompt back when it finishes.

Convert and import sql file into postgresql

I want to migrate database from mysql to postgresql. So, first did the mysqldump with this command
mysqldump -u root -p --compatible=postgresql --default-character-set=utf8 databasename > output.sql
Then i upload the output.sql to host and import the sql file using below command
psql -U root -d databasename -f /home/test/output.sql
But i got error when i try to import
ERROR: syntax error at or near "KEY"
ERROR: syntax error at or near "UNLOCK"
ERROR: syntax error at or near "("
invalid command \n
invalid command \'></script>
invalid command \";s:2:
invalid command \',
invalid command \']
Query buffer reset (cleared).
The size of database that I dumped is 7.5gb.
The SQL used in MySQL and that used in Postgres are not one-to-one inter-compatible. You need a converter program for anything non-trivial.
From the documentation for --compatible:
This option does not guarantee compatibility with other servers.
In other words, it's only slightly more compatible.
There are commercial products like Navicat which can help do this for you automatically, or you can dump out all your MySQL data in a neutral format like XML, JSON or CSV and read it back in using some other tool.

Importing sql file to MySQL

I have a sql file containing data that I want to import to a table on MySQL.
I know the dead easy way is to use a a management software like MySQL work bench and import it that way but I want to learn how to it by command line
I already have sftp the file to the root directly on my linux system but im unsure how to import the data from the .sql file to the table I have in my database.
Use the file as input to the mysql command from the shell command prompt.
$ mysql -h servername -u username -p databasename < filename.sql
You will then be prompted for your password.
If you're already inside the mysql program, you can use its source command.
mysql> source filename.sql

SQL syntax error near gunzip when restoring a database using .sql.gz file

I am trying to restore a mysql db using a .sql.gz file. I am using mySql console to run a command because file size is too large for phpMyAdmin. Command I am using is
gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
where root is the user id. There is no password for root. bd is the database to which I am trying to import. mysql is running on my local machine (Windows 8). I have a wamp setup.
This is the error I am getting:
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'gunzip
C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql | mysql -u root
-p' at line 1.
You need -c option (output to stdout)
gunzip -c xxx.sql.gz |mysql -u root -p
While Kisoft´s answer is the correct one, I just wanted to point out that you don´t need the -c, it works just fine as it is.
this command will unzip the database dump and import it into the database at the same time.
gunzip < output.sql.gz | mysql -u <username> -p<password> <database>
If you type gunzip and you get a SQL syntax error that complaints about gunzip, you are already logged into the mysql console. The mysql console is not a general purpose shell!
You are using Windows and I suspect you haven't installed gzip in your computer (it isn't a builtin utility). It's a classical Unix tool but you can find binaries for Windows. Install it and run your original command with a couple of tweaks:
Make sure you're in Windows prompt (C:\>)
Redirect gunzip result to stdout rather than a file:
gunzip --stdout C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
Alternatively, you can run the dump from within MySQL promt (mysql>) if you uncompress it first (you don't need specifically command-line gzip, most GUI archivers such as 7-Zip support this format):
mysql> \. C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql
you do not need to gunzip
just:
zcat myfile.gz | mysql -uuser -ppassword mydatabase
it is faster this way
Your answer is already here
phpMyAdmin: Can't import huge database file, any suggestions?
Under php.ini file, normally located in c:\xampp\php or wampp whatever you called
post_max_size=128M
upload_max_filesize=128M
Changing value there will get you what you want.Good luck
Dont forget to restart , apache and mysql .
Try this following steps to restore db using .gz files:
1. Run command : gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz
This will uncompress the .gz file and will just store beed_2013-04-06.sql in the same location.
2. Type the following command to import sql data file:
mysql -u username -p bd < C:/Vik/Gya/Source/beed_2013-04-06.sql

Copying a mysql database generates "ERROR: unknown command" when importing

I'm on a japanese system using xampp. This is the line I use to dump my database.
c:\xampp\mysql\bin>mysqldump.exe -uroot wp_newsja > dump.sql
Then I create a database on another server.
c:\xampp\mysql\bin>mysqladmin -uroot create db
But when I try to execute the sql...
c:\xampp\mysql\bin>mysql -uroot db < dump.sql
... I get the following error.
ERROR at line 145: Unknown command '¥''.
On a japanese computer windows path slashes / are represented with "¥". Which leads me to believe this is an utf8 issue. Maybe there is a way I can mysqldump with some utf8 flag? Thanks for any assistance! The exported sql is here: http://goo.gl/7MPVG - Error at line 145:
edit: Problem solved:
mysql --default-character-set=utf8 db < dump.sql
Sorry if I wasted anyone's time.
mysql --default-character-set=utf8 db < dump.sql
You can add this argument --default-character-set=utf8 in the command:
mysql -u USERNAME -p my_database --default-character-set=utf8 < "C:/My Document Names Have Spaces/my_dump.sql"
I've finally found this solution and it works fine with my new installed WampServer 2.5. I've also tried to add the default character setting in my.ini, but it's useless. Until I've tried the above argument added in my DOS batch file.
My batch file execute the command, like this way:
7zip x -so %1.%2.7z|%mysql% -uxxxx -pyyyyy %2 --default-character-set=utf8
For example, the 7zip filename is 20141231.google.7z, which contains "google.sql", and the database name is google
My backup process on Linux system was a 7zip compressed. In Winodws, I used an automatic batch file to restore the same contents, so that I can share the same database in my biz trip and work offline from the server.
Hope this method is helpful to you.