Wordpress to Jekyll script throwing error - mysql

I've been wrestling with this problem for a day or so and cannot figure out what's going on. I'm trying to run a script to import my Wordpress .sql into Jekyll and convert everything to markdown. But every time I run the script (on both Mac and Ubuntu) I'm getting an error. I'm at a loss of what to do. Here's my terminal output and gem list:
jason#ubuntu:~$ ruby -r './wordpress.rb' -e 'Jekyll::WordPress.process( "#{ENV["DB"]}", "#{ENV["USER"]}", "#{ENV["PASS"]}")'
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': LoadError: no such file to load -- mysql (Sequel::AdapterNotFound)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/adapters/mysql.rb:4
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `k_require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:249:in `tsk_require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:72:in `check_requiring_thread'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:69:in `synchronize'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:69:in `check_requiring_thread'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:249:in `tsk_require'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/database/connecting.rb:25:in `adapter_class'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/database/connecting.rb:63:in `connect'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:119:in `connect'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:282:in `adapter_method'
from /var/lib/gems/1.8/gems/sequel-3.22.0/lib/sequel/core.rb:289:in `mysql'
from ./wordpress.rb:35:in `process'
from -e:1
jason#ubuntu:~$ gem list
*** LOCAL GEMS ***
classifier (1.3.3)
directory_watcher (1.4.0)
fast-stemmer (1.0.0)
jekyll (0.10.0)
liquid (2.2.2)
maruku (0.6.0)
sequel (3.22.0)
syntax (1.0.0)
I'm using Paul Stamatiou's adapted script. Thanks ahead of time for any suggestions!

If you focus on the actual error message:
LoadError: no such file to load -- mysql
It's fairly obvious that you need to install the mysql gem:
gem install mysql

Related

Building apache ODE from the source Jruby and Buildr

I need to build apache ODE 1.3.5 from the source. Building from the source is important for me because we plan to make some changes in the ODE code. I tried out their instructions for building. I was able to install jruby 1.5.1 but I was not able to install buildr 1.4.4 using the said version of jruby. I googled a bit and it seemed like I had to upgrade to jruby 1.6.2. After the newer version of jruby(1.6.2), I was able to install buildr 1.4.4 but when I go to the root of the ODE source and execute the following command
buildr package test=no
I get the below exceptions on the console
LoadError: no such file to load -- rubygems/source_info_cache
require at org/jruby/RubyKernel.java:1038
require at c:/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29
(root) at c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/buildr-1.4.4-java/lib/buildr/core/application.rb:41
require at org/jruby/RubyKernel.java:1038
require at c:/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29
(root) at c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/buildr-1.4.4-java/lib/buildr/core/application.rb:17
require at org/jruby/RubyKernel.java:1038
require at c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/buildr-1.4.4-java/lib/buildr/core.rb:29
(root) at c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/buildr-1.4.4-java/lib/buildr.rb:20
require at org/jruby/RubyKernel.java:1038
require at c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/buildr-1.4.4-java/lib/buildr.rb:29
(root) at c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/buildr-1.4.4-java/bin/buildr:18
load at org/jruby/RubyKernel.java:1063
(root) at c:\jruby-1.6.2\bin\buildr:19
I have no idea what I am doing wrong. This is my first interaction with jruby as well as buildr. I appreciate any pointers towards the building of this repository.
Edit 1: Below is the result of jruby -S gem list after installing jruby 1.7.13 and buildr 1.4.19
C:\Users\16030053.CS-6606-DT>jruby -S gem list
*** LOCAL GEMS ***
atoulme-Antwrap (0.7.5 java)
bouncy-castle-java (1.5.0147)
builder (3.2.2)
buildr (1.4.19 java)
bundler (1.15.3)
diff-lcs (1.2.4)
ffi (1.9.3 java)
hoe (3.7.1)
jruby-openssl (0.9.5 java, 0.8.10)
jruby-pageant (1.1.1 java)
jruby-win32ole (0.8.5)
json (1.8.0 java)
json_pure (1.8.0)
krypt (0.0.2)
krypt-core (0.0.2 universal-java)
krypt-provider-jdk (0.0.2)
minitar (0.5.4)
net-sftp (2.1.2)
net-ssh (2.7.0)
orderedhash (0.0.6)
rake (10.1.0, 0.9.2.2)
rdoc (4.0.1)
rspec (2.14.1)
rspec-core (2.14.5)
rspec-expectations (2.14.3)
rspec-mocks (2.14.3)
rubyzip (0.9.9)
xml-simple (1.1.2)
C:\Users\16030053.CS-6606-DT>
Edit 2 When I execute the command buildr package test=no --trace in apache-ode-sources-1.3.5, I get the following errors
F:\apache-ode-sources-1.3.5>buildr package test=no --trace
Buildr aborted!
SyntaxError : F:/apache-ode-sources-1.3.5/tasks/jbi.rake:79: formal argument cannot be an instance variable
Tempfile.open("MANIFEST.MF") { |#jbi_xml_tmp| #jbi_xml_tmp.write descriptor }
^
org/jruby/RubyKernel.java:1081:in `load'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:1:in `(root)'
org/jruby/RubyArray.java:1613:in `each'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:497:in `load_tasks'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:494:in `load_tasks'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:224:in `load_buildfile'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:535:in `standard_exception_handling'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:220:in `load_buildfile'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:130:in `run'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:535:in `standard_exception_handling'
c:/jruby-1.7.13/lib/ruby/gems/shared/gems/buildr-1.4.19-java/lib/buildr/core/application.rb:128:in `run'
org/jruby/RubyKernel.java:1081:in `load'
c:\jruby-1.7.13\bin\buildr:23:in `(root)'
F:\apache-ode-sources-1.3.5>
Below is the response of #sathwik on apache-ode mailing list that helped me compile the ode source for version 1.3.5
Hi Muhammad,
Use jruby 1.7.13 and buildr 1.4.19
Edit file <ode 1.3.5 source>/tasks/jbi.rake. Find and Replace the
initialize method with the content below
def initialize(*args)
super
prepare { path("lib").include((component.libs +
bootstrap.libs).flatten.uniq) }
enhance do
case jbi_xml
when String
path("META-INF").include jbi_xml.path, :as=>"jbi.xml"
when nil, true
# Tempfiles gets deleted on garbage collection, so we're going to
hold on to it
# through instance variable not closure variable.
#jbi_xml_tmp = Tempfile.new('MANIFEST.MF')
#jbi_xml_tmp.write descriptor
path("META-INF").include #jbi_xml_tmp.path, :as=>"jbi.xml"
#jbi_xml_tmp.close
when Proc, Method
#jbi_xml_tmp = Tempfile.new('MANIFEST.MF')
#jbi_xml_tmp.write jbi_xml.call.to_s
path("META-INF").include #jbi_xml_tmp.path, :as=>"jbi.xml"
#jbi_xml_tmp.close
end
end
end
Besides the above changes I had to change line 37 of dependencies.rb
file from
AXIS2_WAR = "org.apache.axis2:axis2-webapp:war:1.3" to
AXIS2_WAR = "org.apache.axis2:axis2-webapp:war:1.6.2"
The above change was needed because all the repositories containing
reference to axis2-webapp:war:1.3 are down. Furthermore, you need to
add following line at the end of repositories.rb file
repositories.remote << "http://people.apache.org/~vanto/m2/"
This is required to fulfill one of the required dependencies namely
xdoclet:xjavadoc-1.1-j5.

JRuby JDBC-mysql error

I have JRuby + Swing application and want to add jdbc/mysql there
require "jdbc/mysql"
But when I'm trying to run it, I have the followig error:
LoadError: no such file to load -- jdbc/mysql
require at org/jruby/RubyKernel.java:1033
(root) at olap_frontend.rb:3
My gem list:
*** LOCAL GEMS ***
activerecord-jdbc-adapter (1.2.2)
activerecord-jdbcmysql-adapter (1.2.2)
bouncy-castle-java (1.5.0146.1)
bundler (1.1.3 ruby)
jdbc-mysql (5.1.13)
jruby-launcher (1.0.12 java)
jruby-openssl (0.7.6.1)
rake (0.9.2, 0.8.7)
rubygems-bundler (0.3.0 ruby)
What I'm doing wrong?
It was my fault - I need to require rubygems first

Ruby on Rails MySQL #08S01Bad handshake - downgrade MySQL?

We recently upgraded from MySQL 5.1.41 to 5.1.61 on our Ubuntu 10.04LTS server. We have an ancient RoR web app that's now giving a bad handshake error:
Mysql::Error in MainController#index
#08S01Bad handshake
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/vendor/mysql.rb:523:in `read'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/vendor/mysql.rb:153:in `real_connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:389:in `connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:152:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `new'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `mysql_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `connection_without_query_cache='
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/query_cache.rb:54:in `connection='
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in `retrieve_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:763:in `columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2060:in `attributes_from_column_definition_without_lock'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/locking/optimistic.rb:45:in `attributes_from_column_definition'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1502:in `initialize_without_callbacks'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in `initialize'
#{RAILS_ROOT}/app/controllers/application.rb:48:in `new'
#{RAILS_ROOT}/app/controllers/application.rb:48:in `log_info'
/usr/local/bin/mongrel_rails:19:in `load'
/usr/local/bin/mongrel_rails:19
I googled around and stumbled onto http://bugs.ruby-lang.org/issues/5017 which tells me it's a Ruby MySQL extension bug. We aren't using the MySQL gem. Our web app is incredibly old and fragile (Ruby v1.8.7, Rails v1.2.3, Mongrel 1.1.5). We're in the process of replacing it with a Django rewrite, so we just need to get this functional for the next few weeks until we will replace it with the new site.
How can we get past this error? I'm thinking that downgrading to MySQL 5.1.41 is the best way to handle this, and then when we begin using the new site in a few weeks, we can re-upgrade to 5.1.61. However, I'm having an issue downgrading mysql. This is the command I'm using:
sudo aptitude install mysql-server-5.1=5.1.41-3ubuntu12.10
However, this tells me Unable to find a version "5.1.41-3ubuntu12.10" for the package "mysql-server-5.1". I've tried sudo aptitude install mysql-server-5.1=5.1.41 also, but that didn't work either. How can I have aptitude install the correct version of MySQL?
Instead of downgrade MySQL gem, it's possible to fix the database name parameter to fix the "bad handshake" problem.
I found this: https://github.com/rubygems/rubygems/issues/423 It's working good.
Instead of doing a hack in real_connect it's possible to add the "\0" in config/database.yml
production:
database: "itsalive_production\0"
adapter: mysql
host: localhost
encoding: UTF8
...
EDIT
If you use the solution with \0 at the end of the database name. You probably will find find out this and solve it yourself, but I mention it anyway:
(at least in my version of Rails)
Using the database string with \0 at the end gives problem when doing rake test. It starts with deleting the test database before copying the development database definitions, and then using a SQL command string that includes the test database name. This will cause an error because of the \0 in the middle of the string.
In my case I'm using a local development database that doesn't give any problem so I don't need to have \0 in that name.
Here is a alternative hack to solve that (original code in mysql_adapter.rb):
module ActiveRecord
module ConnectionAdapters
class MysqlAdapter
alias_method :old_execute, :execute
def execute(sql, name = nil) #:nodoc:
# This is needed because database names can end with "\0" to fix
# the issue with "handshake" when mysql server is newer than the gem
# requires. E.g. called when loading the new test db when doing "rake test".
sql = sql.delete("\0")
old_execute(sql, name)
end
end
end
end
I fixed it! Downgrading MySQL did the trick. We'll re-upgrade to 5.1.61 once the Django site goes live. Here's the command to downgrade MySQL:
sudo aptitude install mysql-server-5.1=5.1.41-3ubuntu12 mysql-client-5.1=5.1.41-3ubuntu12 mysql-server-core-5.1=5.1.41-3ubuntu12
I used apt-cache to get the exact version.
I also had the same issue. Please add:
config.gem 'mysql', :version => '2.7'
Then run rake gems:install.

Standalone script reports "MySQL server has gone away"; problem with my.cnf?

I have a ruby script that requires 'mysql2' and uses query statements to mysql like
#db.query("SELECT sname,id FROM streets where region_id=#{region["id"]}")
but it reports me a error always like this:
main.rb:261:in `query': MySQL server has gone away (Mysql2::Error)
from main.rb:261:in `block (3 levels) in <main>'
from main.rb:258:in `each'
from main.rb:258:in `block (2 levels) in <main>'
from main.rb:254:in `each'
from main.rb:254:in `block in <main>'
from main.rb:253:in `loop'
from main.rb:253:in `<main>'
The script on my Ubuntu is OK, however, my production environment is CentOS and on there I installed MySQL from source code. My Rails app run there is OK and it also requires 'mysql2', but when I run this script it fails.
I think the problem is related to my.cnf but I don't know how configure it.
The mysql2 gem provides an option to reconnect to MySQL in the event that the connection goes away. Rather than updating your my.cnf file, update your gem's database.yml file to include the
reconnect: true
option. This will ensure that the mysql2 gem will attempt to reconnect to MySQL when required.
you call .query method directly on object #db... what exactly is this object?
I mean... if you are under Rails, you should call queries like:
result = ActiveRecord::Base.connection.execute("sql here")
I think it could be the cause, because Rails manages connection pool (eg. 5 established connections and every query goes to one of them, based on requests).
Anyway, if this is not the cause, then it can be that your mysql2 gem is compiled with different version of libmysqlclient.so library on the system...
Then when you try to do a query, it internally throws an error about incompatible protocol and disconnects...
Please check that your libmysqlclient.so and it's header files are of the same version...
Or if you don't have more versions of them installed...
and then please try to recompile mysql2 gem.
Hope this helps.
Regards, NoICE

Rails keeps trying to use SQLite , despite that I've configured MySQL for my project

I setup my rails project "tracks" using:
$ rails --database=mysql tracks # OK
$ cd tracks
$ vim config/database.yml # correct using mysql adapter, added password spec
$ rake db:create RAILS_ENV='development' # OK
$ rake db:migrate # OK
$ ruby script/generate scaffold user name:string password:string email:string url:string # OK
$ rake db:migrate # OK, creates table
$ ruby script/server # OK, starts WEBrick
I open up the thing in a web browser:
http://localhost:3000 # correctly shows the rails welcome splash
I navigate to
http://localhost:3000/users/new
and get a huge slew of errors:
ActiveRecord::StatementInvalid in UsersController#index
SQLite3::SQLException: no such table: users: SELECT * FROM "users"
RAILS_ROOT: /home/drew/tracks/trunk/tracks
Application Trace | Framework Trace | Full Trace
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in `execute'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:372:in `catch_schema_changes'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in `execute'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:275:in `select'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
vendor/rails/activerecord/lib/active_record/base.rb:635:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:1490:in `find_every'
vendor/rails/activerecord/lib/active_record/base.rb:589:in `find'
app/controllers/users_controller.rb:5:in `index'
wtf? Why is ruby still trying to use SQLite? database.yml has zero mention of SQLite.
Thanks
Couldn't figure it out. I ended up reinstalling the OS on the VM and trying again and it worked.
FYI: Do not install rubygems from a package manager like apt-get. Compile it from source or it will all end in tears.
Had this problem, I found all of the files using "find . | xargs grep 'sqlite3' -sl then replaced all of the yml and rb files it found then restarted the server.
Unfortunately, I don't know which (if any, as it may have been the server restart) solved the issue, but now I'm on and up.
Hope that helps someone, however 'hacky'.
Quick Fix that i've used is...
When i start a project a specify the -d for database
rails -d mysql ProjectName
Which builds the database.yml file for mysql
hope this helps.
As odd as it might sound, try clearing your browser's cookies. I had a similar problem moving from sqlite to postgresql and vice versa. It turns out the stored cookie or session was somehow making the server get stuck in using the old database. If this works then you'll want to take steps on your server to invalidate any existing cookies in your users' browsers.
Don't mean to necro, but if someone runs onto this problem, edit your config/database.yml file, and remove the line that says << default from the production section. What this is doing is loading the default environment first, so Passenger loads it instead of whatever else you've configured.