Sequel gem copy database to another with username and password - ruby

From the section to copy another use is to use
sequel -C mysql://host1/database postgres://host2/database2
Is there a way to include username and password for both databases.
Tried with no luck
sequel -C mysql://user:password#host1/database postgres://user2:password2#host2/database2

The usernames and passwords are stored in the user database. You first need to setup a user on your target database. Before that you can't copy anything to it. Copying the user database from mysql to postgres is not going to work either imho so you will have to setup your user manually first.

Related

phpmyadmin: is there any point using dbconfig-common in installation?

The default Ubuntu phpMyAdmin install asks whether dbconfig-common should be used. If you answer Yes, then:
the install creates a new (MySQL) user named phpmyadmin with the password you supply
this user is given rights only to the phpmyadmin database (with only usage on everything else)
the new user's username and password are stored in /etc/dbconfig-common/phpmyadmin.conf, with the passsword in clear
phpMyAdmin is actually installed with auth_type=cookie, so it doesn't need any new users. You can log in as any existing MySQL user.
I'm having trouble understanding what the point of dbconfig-common actually is. User phpmyadmin doesn't appear to be needed, and only has rights on a database that isn't important to the end-user, and creating a new user increases the attack surface. If I drop the phpmyadmin user from MySQL, it doesn't seem to affect phpmyadmin functionality at all, except that I get a warning (access denied for user 'phpmyadmin'#'localhost').
Is dbconfig-common doing something else that's important, or should I try to set up the phpmyadmin config file manually? The current docs appear to be here, but they don't answer the question.

Accessing unencrypted H2 database without credential knowledge

We are cleaning up servers for a customer and have stumbled upon an old application using an H2 database. While the accessing applications have credentials in their configuration files, none of them seem to work.
Even the "sa" user access is not known. As far as I can see, the password for "sa" defaults to an empty string, but access with "sa"/"" is denied (Wrong user name or password [28000-182] 28000/28000 (Help)).
As said, the database is not encrypted. Looking at the file, I can see the SQL statements for the tables, even some table contents.
Is there any way to gain access to that database? As far as my searches have shown it's only possible using the "sa" user. I'm looking for something along the lines of "--skip-grant-tables" from MySQL.
The easiest solution is probably:
Try to login to the database without password. This will fail (wrong user name or password), but it will run transaction log recovery so that the database is in a consistent state.
Then, use the Recover tool (org.h2.tools.Recover) to generate a SQL script.
Edit the script: Change the password for the default user.
Run the script. That way you get a new database.

Setting up a PostgreSQL db for Ruby on Rails locally

I'm stumbling on the real basics because I cannot find any clear directions.
I have installed Postgres.app 9.3.5 on OS X.
The documentation tells me how to create a database, createdb mydb, but to use it I'd need a PostgreSQL user and a password for that user.
What are the basic steps to create a PostgreSQL user with a password (and a database if different than the above) on a local PostgreSQL install?
The Postgres.app documentation used to explain this, but appears to have been split up and cut short recently.
You don't need a dedicated user; you can simply use the default postgres user. However, because that's a superuser, you're wise to create less privileged users for your apps.
You generally want to make a database owned by the app's user, as Rails expects to be able to use the same user to change the schema with migrations as it does to run queries. (It's not great security-wise, but it's the path of least resistance with Rails).
So create the user, then create the db.
Here's how it should look. Don't type the prompts ($ or postgres=#), they're there to show what you're running. Just enter the commands after the prompts.
$ psql -q
postgres=# CREATE USER myapp WITH ENCRYPTED PASSWORD 'mypassword';
postgres=# CREATE DATABASE myappdb OWNER myapp;
postgres=# \q
You may now specify the user, password and database in your database.yml.
(Note that Postgres.app may be configured not to require passwords; in this case the password will be ignored by PostgreSQL).
createdb mydb
psql -s mydb
create user space_pilot password 'hello';
GRANT ALL PRIVILEGES ON DATABASE mydb TO space_pilot;

How do I connect to a postgres database with Sequel?

I was making a web app to deploy using Heroku.com when I realized that the only database type they support is PostgreSQL. Up until now, my app (powered by the Ruby gem Sinatra) accessed the database via the .Sqlite method for the Sequel gem.
Here's my Ruby script from when I used Sequel to access the .db file via SQLite:
DB = Sequel.sqlite('mydatabase.db')
DB.create_table :mytable do
primary_key :id
String :column_name
end
I installed PostgreSQL after learning Heroku used only that. Here's the script via postgres (my username is literally 'postgress', though I obviously won't reveal my password in this question):
DB = Sequel.postgres('mydatabase.db',:user=>'postgres',:password=>'my_password_here',:host=>'localhost',:port=>5432,:max_connections=>10)
DB.create_table :mytable do
primary_key :id
String :column_name
end
However, when I run this code, I get the following error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:208:in 'initialize': PG::Error: FATAL: database "mydatabase.db" does not exist (Sequel::DatabaseConnectionError)
I've tried searching Google, StackOverflow, Sequel documents, and the Heroku help documents for any help, but I've found no fix to this problem.
Does anyone know what I am doing wrong?
The database mydatabase.db doesn't exist, as per the error message from Pg. Likely reasons:
You probably meant mydatabase without the SQLite-specific .db filename suffix
It's possible you created the db with different case, eg "Mydatabase.db";
You might be connecting to a different Pg server than you think you are
You never created the database. Unlke SQLite's default behaviour, Pg doesn't create databases when you try to connect to a database that doesn't exist yet.
If in doubt, connect to Pg with psql and run \l to list databases, or connect via PgAdmin-III.
The PostgreSQL documentation and tutorial are highly recommended, too. They're well written and will teach you a lot about SQL in general as well as Pg in particular.
BTW, the postgres user is a superuser. You should not be using it for your application; it's like running your server as root, ie a really bad idea. Create a new PostgreSQL user without superuser, createdb or createuser rights and use that for your application. You can either CREATE DATABASE somedb WITH OWNER myappuser - or preferably, create the database owned by a different user to your webapp user and then expicitly GRANT the webapp user the minimum required permissions. See user management and GRANT.
On heroku all you need to do is tell Sequel to connect to the content of the DATABASE_URL environment variable (which is a properly formed url that Sequel understands):
DB = Sequel.connect(ENV['DATABASE_URL'])

Installer package for program that uses JDBC to connect to MySQL

I have an installer wizard thing called 'install creator'. I want to include my mySQL database into the installer or find another way that the user, upon installation, can just use my database. Prob is-not everyone has MySQL installed on the computer and even then, the user doesn't know the name of the database or my password. Somehow the database must be created automatically upon install, and for my purposes, some of the tables created. How can one do this. Thanks
If you are just using MySQL as a local storage engine, as it seems to be what you are doing, then you should consider using Sqlite with JDBC, instead of MySQL. MySQL is really intended to be used on a server, where information from multiple users is stored, and where the database is accessed only indirectly through the programs that you create that run on the server. You could, in theory, package up MySQL and MySQL Connector/J which lets JDBC talk with MySQL; however, MySQL is a pretty big beast, and I don't think it's nice to do that to your users (also, don't forget that they might already have MySQL installed, and if you were to install MySQL for the first time, you would effectively be forcing them to use your root password). Unlike MySQL, sqlite is intended to provide the structure of SQL for use with lightweight, local file storage.

Resources