rails windows problem - mysql

I just installed ruby on rails on windows.
install mysql and created a new project. Then I changed database.yml to use my own mysql server as follow
development:
adapter: mysql
database: mytools
username: test
password: test
when I try to access story controller(http://localhost:3000/stories), error shows
"SQLite3::SQLException: no such table: stories: SELECT * FROM "stories" "
Why am I getting this error? I am not using mysql...

By default Rails creates and uses a SQLite database not a MySQL one.
You can specify the database to use with the -d flag when creating your Rails application. For example to create a rails app called "sample" using mysql as the database:
rails sample -d mysql
Taken from the Getting Started with Rails guide.
You might also want to check out the section on Configuring a MySQL Database in the same document.

From what I know - though I was coding in rails long ago, there are 3 separate databases there: development, production and test. Maybe You are trying to use test or production and You didn't configured them?

Did you try a restart on the webserver?
Check if the RAILS_ENV is set to production and if it is, set it for development:
set RAILS_ENV=development

Related

Regenerate YML mapping issue in Symfony 2.4

Running a Symfony 2 project, I have recently made a change in my MYSQL database, and I would like to update my schema and model structure inside my symfony project so I can use the new items that are in it.
This is what I try to do from a running instance in production:
php app/console doctrine:mapping:import --force CoreBundle yml
Here is the error I get:
[PDOException] SQLSTATE[HY000] [2002] Connection timed out
Core/Bundle exists and was already mapped this way by the past
Also note that the server is up and running, doing exchanges with the database
I cannot find a place where to see a more detailed log. Tried to configure the config.yml to add logging for doctrine but it doesn't give me more infos
Thanks in advance
Since I didn't found the source of the problem, I just deployed a new symfony app, connected it to the database and then just generated orm + entities by following the same commands. After that I just copied the /Entity folder and /orm folder and replaced it on my production env. A bit messy but it worked

Can Rails connect to MySQL using MySQL option files?

I'm looking at changing our database connections to use the MySQL configuration utility. Is there a way to tell Rails/ActiveRecord to use .mylogin.cnf instead of specifying connection info in database.yml?
mysql2 gem uses libmysqlclient, which in turn can use .mylogin.cnf starting with 5.6, but there's no way to control its version from rails. Also there seem to be some issues - mysql2 0.4.2 segfaults.
Actually this is possible by setting default_group (= mysql login path) (and default_file if needed) options upon creating mysql2 connection.
But prior to rails 5 these are not passed in connection adapter, but setting blank username and using client login path seems to work.
For example set:
development:
username: ""
default_group: client
database: some_db

Rails integration test: Mysql2::Error: Can't connect to MySQL server

Lately I am working on my beautiful tests, but suddenly, after a 2 days rest, I ran again my integration tests (rake test:integration) and they don't work anymore. I really didn't do anything.
What comes is the following error:
Mysql2::Error: Can't connect to MySQL server on '192.168.0.2'
The nice thing is that the server runs fine. It is just the integration test that is broken. And they use the same mysql database.
Any idea on how to solve the problem?
Luca
check your database.yml settings about test environment and then make in terminal
rake db:test:load
Check the DB using mysql workbench if you not find errors as user permissions... delete and create again DB for app. rake db:drop && rake db:setup

Rails with MySQL v.4.1

Is there any chance to make Rails application connect to old MySQL v4.1.20 server?
rails db
command works fine, but I cannot run the application.
When I generate new app with
rails new app_name -d mysql
I see the following in database.yml file:
MySQL. Versions 4.1 and 5.0 are recommended.
Which should mean I am able to use it.
However Rails Active Record uses MySQL v.5.0.2+ feature (https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb):
# Make MySQL reject illegal values rather than truncating or blanking them, see
# http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
# If the user has provided another value for sql_mode, don't replace it.
if strict_mode? && !variables.has_key?(:sql_mode)
variables[:sql_mode] = 'STRICT_ALL_TABLES'
end
Unfortunately I have nothing to do with old MySQL server version. I have to use it.
Adding
strict: false
to the connector settings in database.yml solved the problem.

Connection problems with Rails and MySQL

So I was making some tests here on Rails and for first time I decide to use MySQL, I've setting up the gem mysql2 and the mysql server.
When I try to access the database I receive this:
ActiveRecord::ConnectionNotEstablished
The strange thing is I'm able to run the rake db:create and the migrations without any problems.
thanks in advance,
Renan
ActiveRecord::ConnectionNotEstablished
Raised when connection to the database could not been established (for example when connection= is given a nil object).
Try checking your db configurations in the config/database.yml file if everything is correct or not!!