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.
Related
I'm trying to deploy mediawiki to Azure Web App. I created the app using Linux and PHP 7.3. I unpacked WikiMedia 1.35.1 into wwwroot and used the browser to run the installation
I want to use MySQL for Azure as the database. So I enter the mysql.database.azure.com parameters and press install.
The error I get is
Cannot access the database: :real_connect(): (HY000/9002): SSL connection is required.
The docs say I need to set $wgDBssl to true in LocalSettings.php.
The problem is that LocalSettings.php does not exist yet. How do I specify an SSL connection during installation?
I am trying to figure out the same dilemma and hoping someone with more PHP knowledge can provide a better answer. As a work around, you can disable "Enforce SSL" on your MySQL database in Azure. Then you can run the setup, create the localSettings.php file. After which you can add the settings for $wgDBssl and re-enable enforce ssl setting.
To my knowledge, a connection to the database is being using the "/includes/installer/MysqlInstaller.php" when running the setup. In the "DatabaseMysqli.php" and "Database.php" of /includes/libs/rdbms/database/ directory these two files are used for connecting to the database when running any query.
I am trying to see if there is a way to set the SSL setting in these 3 files first then run the setup and application. Apologies that I've entered this as an answer also. I am new to StackOverflow and cannot create comments yet.
I was able to work around this issue by forcing the following clause in /includes/libs/rdbms/database/DatabaseMysqli.php to always be true by adding || true at the right place between the two closing parentheses:
if ( $this->getFlag( self::DBO_SSL ) || true ) {
$flags |= MYSQLI_CLIENT_SSL;
$mysqli->ssl_set(
$this->sslKeyPath,
$this->sslCertPath,
$this->sslCAFile,
$this->sslCAPath,
$this->sslCiphers
);
}
Maybe there's a more elegant way to make the original condition $this->getFlag( self::DBO_SSL ) to evaluate as true naturally?
In a ruby script (not rails) Iam using mysql. Because my mysql are available in a .my.cnf file, I can use mysql on the terminal without password. But that does not work in a ruby script, how can I achieve that?
If you are using mysql2, you may need to read the .my.conf manually, as show in the doc
Reading a MySQL config file
You may read configuration options from a MySQL configuration file by
passing the :default_file and :default_group parameters. For example:
Mysql2::Client.new(:default_file => '/user/.my.cnf', :default_group =>
'client')
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
How to force MySQL reconnect at my will in Rails application? I would like to do this either periodically or on DB exceptions like "MySQL server has gone away".
I found ActiveRecord::Base.remove_connection but as it is written, it should be called for some model, not the whole application.
It's a huge pain to restart the Rails console when I'm running it via Heroku with a bunch of objects in variables and then lose my database connection.
The following is code I would not consider "good" to put in your actual application but it temporarily gets over the oft encountered Mysql2::Error: closed MySQL connection in a console:
ActiveRecord::Base.connection.reconnect!
How about using reconnect = true in your database.yml as described here?
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