connect Rails application to a MySQL server - mysql

I'm trying to install MySQL adapter to connect my Rails application to a MySQL server, but when I try the command:
gem install mysql2
it return this error message:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.
How can I fix it?
Thanks,RC

You don't have write permissions into the /Library/Ruby/Gems/1.9 directory.
means exactly that, you don't have permission to write there.
That is the version of Ruby installed by Apple, for their own use. While it's OK to make minor modifications to that if you know what you're doing, because you are not sure about the permissions problem, I'd say it's not a good idea to continue along that track.
Instead, I'll strongly suggest you look into using either rbenv or RVM to manage a separate Ruby, installed into a sandbox in your home directory, that you can modify/fold/spindle/change without worrying about messing up the system Ruby.
Between the two, I use rbenv, though I used RVM a lot in the past. rbenv takes a more "hands-off" approach to managing your Ruby installation. RVM has a lot of features and is very powerful, but, as a result is more intrusive. In either case, READ the installation documentation for them a couple times before starting to install whichever you pick.

Related

Postfix install fails. MySQL conflict

I'm using CentOS 6, and trying to create a virtual mirror on a new server of an old one (which someone else setup). As much as possible, I want keep everything with the same version, but I've started from scratch and am documenting everything. By default, yum would install MySQL 5.1.73. I downloaded MySQL community v5.1.69 and installed it manually. This required installing a "shared compatibility" package of MySQL v5.1.69 first, and removing mysql-libs.x86_64. With that in place, I successfully mirrored MySQL.
Now, I'm trying to install Postfix. Yum wants to pull version 2.6.6-6. This fails because it requires a dependency that it attempts to install as well: mysql-libs.x86_64 v.5.1.73-5. It splits out a pile of errors messages which are all similar to this:
Transaction Check Error:
file /usr/share/mysql/charsets/Index.xml from install of mysql-libs-5.1.73-5.el6_6.x86_64 conflicts with file from package MySQL-server-community-5.1.69-1.rhel5.x86_64
My old server is using postfix v2.6.6-2, which is apparently compatible with MySQL v5.1.69. I found the rpm for that version of postfix. It doesn't install, because it requires mysql-libs. I can't install mysql-libs v.5.1.69, because it conflicts with the MySQL community edition (also 5.1.69) that I installed. I tried to install the MySQL 5.1.73 "shared compatibility" package, but that conflicts with MySQL community too.
I'm going in circles. Is the only way to break this chain to uninstall MySQL community? Must I just use the v5.1.73 default, and the Postfix 2.6.6-6? I don't expect any real problems, but I'm going to end up with slightly different versions of MySQL and Postfix then I am trying hard to mirror.
I gave up, uninstalled all the MySQL community packages, and just installed the out of the box yum MySQL and Postfix. That works, but I now have different versions of this software on these two servers as a result.

using mysql in lua script

I need to read a database table from inside a Lua script in pdns-recursor on a Scientific Linux 6.4 server which comes with Lua pre-loaded.
Apparently I have to use luarocks to install luasql. When I attempt to install luasql I get:
Checking Lua includes... lua.h not found
lua.h is not on the server.
I tried removing the installed version so I could install from binary but then that trashed the system which apparently uses the installed Lua for everything (yum, rpm, etc). Now I have to reload OS. How can I get MySQL access from embedded Lua?
Thanks in advance.
I assume that you have already checked yum to see if luasql is available through that; if not, you should first do that, and install it through yum if possible.
The immediate cause of the problem you're having is that luarocks automatically builds modules from source, which requires access to the lua headers. These are not needed simply to run programs that use Lua, so they are not installed as part of the normal Lua package. I'm not familiar with Scientific Linux, but you can probably get them by installing a package named lua-dev, lua-devel, lua-headers, or some variant thereof. You may also need the mySQL packages (both the libraries proper and the headers). Once you have those installed, give it another try.
You might also try LuaDist, which I find to be generally more polished than luarocks, and capable of automatically downloading more dependencies; in particular it probably will not require the lua headers installed, and can handle automatically downloading and installing lua itself from source. It does, however, require CMake installed.
If for some reason you can't install the required headers and can't get luarocks or luadist working, you can try downloading and building luaSQL by hand. The Lua headers can be found in the Lua 5.1 source package and LuaSQL 2.2. Assuming the Scientific Linux maintainers haven't excessively customized the version of lua they ship with it, the results should be compatible with the system Lua install.

ruby on rails with multiple databases ( mongodb, mysql )

I'm planning to use multiple databases (mongodb, mysql) for my project.
And I have no idea with it.
Is there anyone can tell me how to connect mongodb and mysql to rails?
or any references?
Thanks.
-I'm using Ruby 1.9.3 and Rails 3.2
You need to setup your rails project with both of the database connections.
Firstly for Mongo, you need to decide which driver wrapper (if you use one) are you going to use. The two common ones are MongoID & MongoMapper. Both do pretty much the same thing and make it easy to interact with Mongo in a similar fashion to ActiveRecord.
To install these you merely install the appropriate gem e.g. for mongomapper you need to run 'gem install mongomapper'
Follow these Railcasts for step by step instructions:
MongoMapper or
MongoID
Now for mysql, again there is a gem to install, 'gem install mysql', and then follow the instructions on the 'getting started' ruby on rails guide to configure your database files.
Remember for both mongo & mysql you will need to have them installed and running somewhere that it accessible from development environment

Facing lot of problems while using ROR

I am new to Ruby on Rails. I have read many article regarding easy installing steps. I installed ruby on windows. After starting the server i got welcome message too. After that if i add a controller I got this message on browser.
And also when tried to do a rake db:migrate i get the error saying mysql gem is missing.
I have installed mysql 5.0. I tried updating gem using this command and got this error.
C:\Documents and Settings\dchannap\Desktop>gem install mysql
ERROR: http://rubygems.org/ does not appear to be a repository
ERROR: Could not find a valid gem 'mysql' (>= 0) in any repository
My gem version is 1.3.7. and ruby is 1.9.1.
Can anyone help me in this regard. I hav to do a project on ROR..
Its probably internet connection or server side problem.
Here is similair question
You'll find it much easier to get started using SQLite3. Why not go with the flow for now? When you need to go more advanced you'll have much more experience with Ruby and Rails and Gems and you'll find it much easier to get sorted.
Are you behind a proxy? In that case you will have to specify it. E.g.
gem install --http-proxy http://your-proxy-address:8080 mysql
Thanks for all the replies.. I learnt Rails on Windows will face problems. And just tried with Instant rails. I faced no problems at all. I am able run small applicatins now.

Incompatibily between ruby and mysql gem

When trying to install the mysql gem from cPanel on my website, I get an error saying that the gem requires Ruby >= 1.8.6.
This is a shared server and the version of Ruby is 1.8.5 and can't be upgraded.
I do not have shell access and it seems the only way for me to install a gem is through the list of gems within cPanel.
How can I get mysql for my website?
You can try to install an older gem. 2.7.5 seems to be the proper version.
Ruby 1.8.5 is pretty old and as far as I know hasn't been actively supported by Rails for a while. You really need 1.8.6 and preferably 1.8.7. If your host won't upgrade it may be time to look elsewhere. If you really have no other option, you should to what Yuval suggests and try installing an older version of the gem.
No one having answered how to install a gem without shell access, I'll assume it can't be done and so will accept my own answer.