Often connection problem with the database are due to the Ruby MySQL bindings. For performance considerations it’s better to have the mysql-ruby C bindings installed.
This is a known problem on Ubuntu. To get rid of this message install libmysql-ruby.
apt-get install libmysql-ruby1.8
I had the same problem on Debian, “lost connection…” and this fixed it.
Gentoo users:
emerge mysql-ruby
On Fedora:
yum install ruby-mysql.i386
make sure that mysql-devel is installed and that you have run ldconfig.
gem install mysql
gem install mysql -- --with-mysql-dir=/usr/local/mysql
I found the following worked for me (Fedora core 3):
gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
It seems most simplified with gem (It works on Fedora Core 4):
gem install mysql -- --with-mysql-config=`which mysql_config`
On CentOS 4.5:
Install any supporting packages (note CentOS does not include a “ruby-mysql” package.)
yum install mysql-devel ruby-devel gcc
gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysqlOn Windows:
gem install mysql
If this doesn’t install, look here (this solved it on RHEL4)
Also, it’s generally advisable to insure you have mysql-devel installed before attempting to build your own mysql C bindings.
Problems on Windows still?
An alternative MySQL/Ruby distribution for Windows is at http://www.vandomburg.net/pages/mysql-ruby-windows that seems to solve all the corner-cases.
Something else to try
If your code fails after running at least one query successfully, and you are running on WEBrick, apply this patch to your code: http://dev.rubyonrails.org/ticket/3433
It May be as Simple as Passwords
Really, check that any passwords for user(s), database(s), connection(s), and database.yml match. I happen to be using a GUI to interact with my MYSQL databases and by simply editing my users’ and the database connection’s passwords I was able to get rid of the “lost connection” and “access denied for user…” errors.
Flush Privileges
I solved this problem by simply running FLUSH PRIVILEGES after my GRANT statement(s).
This is another solution
I found a completely different solution at HowTosWorkerThreads
Using Solaris 10?
I tried doing pretty much everything mentioned above (installed the gem, password modifications, etc)...along with numerous suggestions from sites I could find via Google. In the end, I installed MySQL/Ruby 2.7.1 from the source and it worked like a charm. I am running
Heed the default database.yml
“And be sure to use new-style password hashing:”
http://dev.mysql.com/doc/refman/5.0/en/old-client.html
I used the mysql_fix_privilege_tables script to upgrade the mysql.user table on my installation. Note that the server must be restarted for mysql to notice the change in size of the password field.
Then, change your mysql password so it gets the new style hashing. New style passwords begin with a ’*’.
See the man page for all the details:
man mysql_fix_privilege_tables
Once I upgraded to the new style hashing, the error disappeared.
The gem installation lacks symlinking the shared object file where require method looks for it, /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
so just symlink mysql.so → lib/mysql.so under the same directory.
Often connection problem with the database are due to the Ruby MySQL bindings. For performance considerations it’s better to have the mysql-ruby C bindings installed.
This is a known problem on Ubuntu. To get rid of this message install libmysql-ruby.
apt-get install libmysql-ruby1.8
I had the same problem on Debian, “lost connection…” and this fixed it.
Gentoo users:
emerge mysql-ruby
On Fedora:
yum install ruby-mysql.i386
make sure that mysql-devel is installed and that you have run ldconfig.
gem install mysql
gem install mysql -- --with-mysql-dir=/usr/local/mysql
I found the following worked for me (Fedora core 3):
gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
It seems most simplified with gem (It works on Fedora Core 4):
gem install mysql -- --with-mysql-config=`which mysql_config`
On CentOS 4.5:
Install any supporting packages (note CentOS does not include a “ruby-mysql” package.)
yum install mysql-devel ruby-devel gcc
gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysqlOn Windows:
gem install mysql
If this doesn’t install, look here (this solved it on RHEL4)
Also, it’s generally advisable to insure you have mysql-devel installed before attempting to build your own mysql C bindings.
Problems on Windows still?
An alternative MySQL/Ruby distribution for Windows is at http://www.vandomburg.net/pages/mysql-ruby-windows that seems to solve all the corner-cases.
Something else to try
If your code fails after running at least one query successfully, and you are running on WEBrick, apply this patch to your code: http://dev.rubyonrails.org/ticket/3433
It May be as Simple as Passwords
Really, check that any passwords for user(s), database(s), connection(s), and database.yml match. I happen to be using a GUI to interact with my MYSQL databases and by simply editing my users’ and the database connection’s passwords I was able to get rid of the “lost connection” and “access denied for user…” errors.
Flush Privileges
I solved this problem by simply running FLUSH PRIVILEGES after my GRANT statement(s).
This is another solution
I found a completely different solution at HowTosWorkerThreads
Using Solaris 10?
I tried doing pretty much everything mentioned above (installed the gem, password modifications, etc)...along with numerous suggestions from sites I could find via Google. In the end, I installed MySQL/Ruby 2.7.1 from the source and it worked like a charm. I am running
Heed the default database.yml
“And be sure to use new-style password hashing:”
http://dev.mysql.com/doc/refman/5.0/en/old-client.html
I used the mysql_fix_privilege_tables script to upgrade the mysql.user table on my installation. Note that the server must be restarted for mysql to notice the change in size of the password field.
Then, change your mysql password so it gets the new style hashing. New style passwords begin with a ’*’.
See the man page for all the details:
man mysql_fix_privilege_tables
Once I upgraded to the new style hashing, the error disappeared.
The gem installation lacks symlinking the shared object file where require method looks for it, /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
so just symlink mysql.so → lib/mysql.so under the same directory.