Convert and import sql file into postgresql - mysql

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.

Related

Can't import file dumped by mysqldump

I created a dump from a database that we have on a kube pod as follows:
kubectl exec mysql-0 -n pod-name -- mysqldump -u root -ppass dbname > ~/Desktop/dump.sql
I then try to import this database into my local db by:
mysql ebdb --force -uroot -proot < ~/Desktop/dump.sql
But I keep getting errors as:
ERROR 1064 (42000) at line 4550: 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 ''---\nid: 195\nrestaurant_id: 4330\napi_key: sk_live_wVi93Gt11111puIE\nm' at line 1
I repeated the dumping and importing multiple times with similar errors: syntax problems.
I thought maybe the error has to do with encoding, so I dumped using
kubectl exec mysql-0 -n pod-name -- mysqldump -u root -ppass --default-character-set=utf8 ebdb > ~/Desktop/dump.sql
but still same error.
Any ideas about what might be going wrong here?
p.s: Of course I'm changing the name of the pod and pass here as well as some of the chars in the api key for obvious reasons. Otherwise things are left as is

MySql error when importing dump from linux into windows machine localhost

I get a couple of errors when trying to import a .sql dump file using the following command:
mysql -hIP -r -uroot -p db_test < C:\Users\Mark Hur\SQL Dumps\oct.sql;
The errors I get are as follows:
ERROR:
Unknown command '\U'.
ERROR:
Unknown command '\O'.
ERROR:
Unknown command '\P'.
ERROR:
Unknown command '\D'.
ERROR:
Unknown command '\S'.
ERROR:
Unknown command '\o'.
I guess these are due to the fact that I received a .sql dump from a database that resides on a linux machine. How do I import it then? I want to to import the data only
Since you are using a long filename with spaces it needs to be quoted:
mysql -hIP -r -uroot -p db_test < "C:\Users\Mark Hur\SQL Dumps\oct.sql"
Reference:
Long Filenames or Paths with Spaces Require Quotation Marks

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

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

import a sql file using mysql command line tools

here is my command to import a sql file into mysql using command line
mysql -p eshop < c:\xampp\mysql\eshop.sql
But there is error message
Error:
Unknown command '\x'
Error:
Unknown command '\m'
Error:
Unknown command '\e'
Anyone knows what's wrong with the command?
Try this, I think this may help you.
mysql -u username -p database_name < file.sql
check mysql Options. Don't use \ (slash) use / (slash) to mention the file path.
On Windows, the pathname separator character is
‘\’, but MySQL treats the backslash as the escape character in strings. To deal with this
issue, write separators in Windows pathnames either as ‘/’ or as ‘\\’. To load a file named
C:\mydata\data.txt, specify the filename as shown in either of the following statements:
mysql <database_name> < ‘C:/mydata/data.txt’
mysql <database_name> < ‘C:\\mydata\\data.txt’

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