Facing issue in Postgres loading extension - gis

I am trying to to load pgrouting in extension in postgis database named as "routing" the problem I am facing is I type in osgeo shell in "C:\Program Files (x86)\Boundless\OpenGeo\bin" "psql -U postgres routing" and it gives the error of "psql : illegal option --u"

Are you sure, that your wrote "-U" and not "-u" in lower case? Because this is what the error tells you. If you connect to the database routing using: psql -U postgres routing then it should be all right.

Related

Shifting database from MySQL to Postgres

I have a database in MySQL which can be accessed using Microsoft SQL Server Management Studios. I have a .bak file of that database and I want to shift this database to Postgres.
I went to the command line and I opened the directory of my Postgres to the bin folder from the program files, and I wrote the command :
psql -U postgres -d postgres < (directory of the .bak file)'
I got the following error on running the above command:
ERROR: syntax error at or near "TAPE"
LINE 1: TAPE
Can someone please explain why I am getting this error and how to resolve it?

How to Export MySQL Database From Digital Ocean Managed Database

I have a MySQL database hosted on Digital Ocean Managed Database service. I lost my previous dev machine and did not push the Schema to git along with application files. I am desperate to get back the SQL Schema in my local machine for further Development but have so far been usuccessfull. I have tried so many commands from different suggestions but they all failed.
I connect to the DB via the MySQL Shell using the command:
mysql -u username -password-h example-test-do-user-7878789-0.b.db.ondigitalocean.com -P 25060 -D example_db
All queries are executed successfully via this shell method. When trying to Dump the Schema to my machine, I use the following command:
mysql -u username -p -h mysql-test-do-user-4915853-0.db.ondigitalocean.com -P 25060 your_database_name \> database_file_name.sql
But I get the error as follows: mysqldump: unknown variable 'set-gtid-purged=OFF'
if I remove that part and try again, I get the error:
mysqldump: Got error: 2003: "Can't connect to MySQL server on 'localhost' (10061 "Unknown error")" when trying to connect
which doesnt make sense to me. So, without further ranting; How to I achieve my intended result.
NOTE: I did try Mysql workbench, but it won't connect all together
I can appreciate trying to achieve what you want via mysql shell. I stumbled across the same problem and for quite some tie did not find the help i needed, then I tried doing it using mysql workbench. Try it and you will find that its easier than usin the command-line approach. MySQL Workbench has a good GUI based database miguration capability. You can migrate you Do Managed DB directly into you local mysql server or export a schema dump. If you decide to go wit this approach, just make sure you add your machine's IP as a trusted source, else you will not be able to connect.

MySQL 5.6 / Data export doesn't work (dumping data)

What I've been trying to do is to send some data from MySQL to other computers.
I searched the internet for a solution and the best way is probably to put the data into a file, by using the export function.
Soon I encountered an error. Here is part of the log.
Running: "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
--defaults-file="c:\users\takaha\appdata\local\temp\tmpx2hr0e.cnf"
--enable-cleartext-plugin --user=root --host=localhost --protocol=tcp
--port=3306 --default-character-set=utf8 --events --skip-triggers "db_student_comments"
mysqldump: unknown option '--enable-cleartext-plugin'
Operation failed with exitcode 2
14:44:03 Export of C:\Users\takaha\Documents\dumps\Dump20150212.sql has finished with 1 errors
Apparently, this error is similar to this error, but trying the first and second advice on this page didn't solve it, and I've spent more than two days in this problem so far.
I'll put a image of my cmd, since using cmd was recommended at other Stackoverflow pages. This image shows the dumping seems to have successfully been done, but I don't know where the file is. (The "dump" folder was automatically created in C:\Users\username\Documents, but this folder is empty.)
I'd appreciate any advice.
EDIT
Thanks to Danyal, this was solved.
All I had to do was to exactly indicate the directory to create the file after ">".
why don't you use this command?
mysqldump -u'username' -p'password' database_name > back_up.sql
You need to have mysql in the environment variable. If it isn't there, you can go to mysql's bin directory and can execute this command.
Per the docs:
The mysql, mysqladmin, and mysqlslap client programs support an --enable-cleartext-plugin option that enables the plugin on a per-invocation basis.
It does not appear to be a valid option for mysqldump. You shouldn't need it at all unless you're using non-standard MySQL authentication.

Where can I run a mysql command line under Azure to fix "The used command is not allowed with this MySQL version (1148)"

I have a MySQL database which is hosted in Azure, and I have MySQL Workbench installed on my laptop. I want to do some importing from a CSV file located in my laptop, but whenever I try to that, I get an error message saying:
The used command is not allowed with this MySQL version
I did some online searching, and I found out that I need to run the following command:
mysql -u myuser -p --local-infile somedatabase
But, I don't know where I have to run it, and how, while as I said my database is hosted in Azure.
mysql is just the commandline executable of the MySql client. And most probably it is even part of the MySql workbech - just check the MySQL Workbech working folder. But the result will not be different is my guess.
The best way you can manage Import/Export for MySQL is to use a Free Tier WebSite and Install the phpMyAdmin extension.

Is there a simple tool to convert mysql to postgresql syntax?

I've tried the tools listed here, some with more success than others, but none gave me valid postgres syntax I could use (tinyint errors etc.)
There's a mysqldump option which makes it output PostgreSQL code:
mysqldump --compatible=postgresql ...
But that doesn't work too well.
Instead, please see the mysql-to-postgres tool as described in Linus Oleander's answer.
Try this one , it works like charm !!
http://www.sqlines.com/online
After some time on Google I found this post.
Install the mysql2psql gem using [sudo] gem install mysql2psql.
Create a config file by running mysql2psql. You'll see an error but a mysql2psql.yml file should have been created.
Edit mysql2psql.yml
Run mysql2psql again to migrate you data.
Tip: Set force_truncate to true in your mysql2psql.yml config file if you want the postgresql database to be cleared before migrating your data.
Install pgloader on Debian or Ubuntu:
sudo apt install pgloader
Login as the postgres user and create a database
sudo su postgres
createdb -O user db_migrated
Transfer data from the mysql database to postgresql
pgloader mysql://user#localhost/db postgresql:///db_migrated
Check also Dimitri Fontaine's rewrite of pgloader from python to common lisp so that he could implement real threading.
Installation on other platforms
To install pgloader on Windows, you can use the Windows Subsystem for Linux.
To install pgloader on Mac, you can use: brew install --HEAD pgloader.
I've used py-mysql2pgsql. After installation it needs only simple configuration file in yml format (source, destination), e.g.:
# if a socket is specified we will use that
# if tcp is chosen you can use compression
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: mysql2psql
password:
database: mysql2psql_test
compress: false
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: mysql2psql
password:
database: mysql2psql_test
Usage:
> py-mysql2pgsql -h
usage: py-mysql2pgsql [-h] [-v] [-f FILE]
Tool for migrating/converting data from mysql to postgresql.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Show progress of data migration.
-f FILE, --file FILE Location of configuration file (default:
mysql2pgsql.yml). If none exists at that path,
one will be created for you.
More on its home page https://github.com/philipsoutham/py-mysql2pgsql.
Have a look at PG Foundry, extra utilities for Postgres tend to live there. I believe that the tool you're looking for does exist though.
There is one piece of pay software listed on this postgresql page:
http://www.postgresql.org/download/products/1
and this is on pgFoundry:
http://pgfoundry.org/projects/mysql2pgsql/
This page lists the syntax differences, but a simple working query converter i haven't found yet. Using an ORM package instead of raw SQL could prevent these issues.
I'm currently hacking up a converter for a legacy codebase:
function mysql2pgsql($mysql){
return preg_replace("/limit (\d+), *(\d+)/i", "limit $1 offset $2", preg_replace("/as '([^']+)'/i", 'as "$1"', $mysql)); // Note: limit needs order
}
For CREATE statements, SQLines converts most of them online. I still had to edit the mysqldump afterwards, though:
"mediumtext" -> "text", "^LOCK.*" -> "", "^UNLOCK.*" -> "", "`" -> '"', "'" -> "''" in 'data', "0000-00-00" -> "2000-01-01", deduplicate constraint names, " CHARACTER SET utf8 " -> " ".
"int(10)" -> "int" was missed in the last table, so pass that part of the mysqldump through http://www.sqlines.com/online again.
you will most likely never get a tool for such task which would do all of your job for you. be prepared to do some refactoring work yourself.