So, I'm using the mysql2psql gem and I've got the following code:
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: root
password: root
database: hello_development
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: root
password: root
database: hello_development
# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false
I'm a bit confused though, as to how I would convert all of my table e.g. test, and production as well. At the moment, it looks like I am just converting hello_development.
Please advice!
You're specifying which database to use - database: hello_development - which is why it's only running in your development environment. You need to create config files for mysql2pgsql for your test and production environments as well.
Having used mysql2pgsql in the past, keep in mind that there can be a LOT of differences between how mysql and postgres work - make sure that you have fully tested your application in a development environment prior to running this script in your production environment.
Related
Am using long2ice/synch tools for mysql to clickhouse data replication on a specific table, but when am running the below command > synch --alias mysql_db etl -h getting error
synch --alias mysql_db etl -h usage: synch [-h] [-c CONFIG]
[--version] {etl,produce,consume} ... synch: error: invalid choice:
'mysql_db' (choose from 'etl', 'produce', 'consume')
How to resolve the above error.
configuration file as it is, below as am mention
db_type: mysql
alias: mysql_db # must be unique
broker_type: redis # current support redis and kafka
server_id: 1
host: 127.0.0.1
port: 3306
user: root
password: "12345"
# optional, auto get from `show master status` when empty
init_binlog_file:
# optional, auto get from `show master status` when empty
init_binlog_pos:
skip_dmls: # dmls to skip
skip_delete_tables: # tables skip delete, format with schema.table
skip_update_tables: # tables skip update, format with schema.table
databases:
- database: test
Anything i am missing above configuration.
Thanks,
Bimal.
try to use following config
core:
debug: true
source_dbs:
- db_type: mysql
alias: mysql_db # must be unique
broker_type: redis # current support redis and kafka
server_id: 1
host: 127.0.0.1
port: 3306
user: root
password: "12345"
and run
synch --alias mysql_db etl
I'm looking for help or documentation if it is possible to dump multiple sql dump files using codeception, and use a configuration like this:
modules:
config:
- Db:
dsn: 'sqlite:./var/cache/test/test.sqlite'
user: ''
password: ''
=> dump: 'tests/_data/*.sql' <=
populate: true
cleanup: true
reconnect: true
You can now do it with
- Db:
dsn: 'sqlite:./var/cache/test/test.sqlite'
user: ''
password: ''
dump:
- 'tests/_data/d1.sql'
- 'tests/_data/d2.sql'
I don't think that is possible straight out of the box.
An alternative would be to combine the dumps into 1 dump file.
You can also have a look at my answer to this post, maybe it can be helpful for you.
I have a rails app that uses mysql as the database. I've done an sqldump, created a database (called local_prod), and imported the dump into the database. When I try to access the database information with my rails app, it doesn't see any of the data that is in the database. Any idea why this is happening?
When I call for the object I'm looking for through the web app, it returns nil. Here is the sql select statement that is run:
Bound Load (0.5ms) SELECT `bounds`.* FROM `bounds` WHERE `bounds`.`city` = 'boston' AND `bounds`.`state` = 'ma' ORDER BY `bounds`.`id` ASC LIMIT 1
When I copy and paste that same statement into the mysql console in my terminal, it returns all the data I am looking for.
Here is my database.yml file as well:
development:
adapter: mysql2
database: local_prod
host: localhost
username: root
password:
socket: /tmp/mysql.sock
You sure your sql db doesn't have a root password?
Im making an application with a pre-existing database, I set up the database.yml to use the database.
database.yml
development:
adapter: mysql2
encoding: utf8
# database: ttlem_demo_development
database: ttle
pool: 5
username: root
password:
socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
database: ttlem_demo_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
database: ttlem_demo_production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
I only want one table out of the database it is called account views, I try to generate a scaffold for this with all the correct fields but it tells me i need to migrate (when i render it in the browser), if i migrate i wont be able to use the existing data, is this correct? How can i make a model that will use the existing data and fields?
Thank you for all your help :)
Two things to try:...
#1 Run your scaffold without a migration so it doesn't think you're missing one.
rails g scaffold yourmodelname fieldone:fieldtype ... etc --no-migration
#2 If that doesn't work you can go the long way round but dumping and reloading with a valid schema version number
Add this db to yml to your gemfile:
gem 'yaml_db', github: 'jetthoughts/yaml_db', ref: 'fb4b6bd7e12de3cffa93e0a298a1e5253d7e92ba'
It works for either rails 3 or rails 4.
Do a schema dump of your current database so you'll get a schema.rb with a valid version number.
bundle exec rake db:schema:dump
Now that you have a valid schema dump your data.
bundle exec rake db:data:dump
Drop your database (you can do it manually using the mysql commands if you prefer or run rake db:drop)
Now recreate it with your schema file.
bundle exec rake db:schema:load
Now add back your data
bundle exec rake db:data:load
Start your server and assuming your correctly matched all your data fields in your model (so the proper strong parameters are set from your scaffold) you should be good.
Trying to convert my MYSQL db to postgreSQL so it will play nicely with heroku. I installed the gem mysql2psql and run it. When I run it, I get...
mysql2psql
Creating table breads...
Created table breads
Creating table sammiches...
Created table sammiches
Creating table schema_migrations...
Created table schema_migrations
Counting rows of breads...
Rows counted
Loading breads...
33 rows loaded in 0min 0s
Counting rows of sammiches...
Rows counted
Loading sammiches...
161 rows loaded in 0min 0s
Counting rows of schema_migrations...
Rows counted
Loading schema_migrations...
4 rows loaded in 0min 0s
Indexing table breads...
Indexed table breads
Indexing table sammiches...
Indexed table sammiches
Indexing table schema_migrations...
Indexed table schema_migrations
Table creation 0 min, loading 0 min, indexing 0 min, total 0 min
if I am in pg:psql I can run queries and I know that the columns imported correctly to the table, but there are no entries...
I tried-
heroku rake db:migrate
WARNING: `heroku rake` has been deprecated. Please use `heroku run rake` instead.
Running `rake db:migrate` attached to terminal... up, run.6669
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
Connecting to database specified by DATABASE_URL
Migrating to CreateSammiches (20130428211616)
But it is still empty. Empty likeeeee
dbl77pdgmr9l10=> select * from sammiches; id | name | image | country | description | created_at | updated_at
----+------+-------+---------+-------------+------------+------------
(0 rows)
dbl77pdgmr9l10=>
Any ideas? Thanks!
mysql2psql file-
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: root
password: ####
database: sandwich_development
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: root
password:
database: pgmysql_db
# if tables is given, only the listed tables will be converted. leave empty to convert all tables.
#tables:
#- table1
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- table3
#- table4
# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: false
# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: false
# if force_truncate is true, forces a table truncate before table loading
force_truncate: false
Check your database.yaml configuration
suppress_data: true
Might be not moving data, only schema