I have mysql server installed and it contains data also. I was trying to connect to mysql from ruby code. For that purpose I installed mysql gem using gem install mysql
. The connection part in my program is giving below
require 'rubygems'
require 'mysql'
require 'csv'
$user_name = "root"
$pas_wrd = "password"
def mysql_connect(db_name)
begin
db = Mysql.real_connect("localhost", "#{$user_name}", "#{$pas_wrd}", "#{db_name}")
return db
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
end
end
It was written some day before and done the job. But when I try to use the same code It shows a mysql gem error,something like 'initialize' not found. By searching I found a solution like re-installing the gem. for re-installing I user the command rvmsudo gem install mysql
. The above problem was solved. But it showing another error like
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I tried manually using mysql -u root -p
it is also showing the same error.
My mysql my.cnf
content is given below.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
tmpdir = /home/presoft/Documents
skip-external-locking
The mysql is not running in my system.
ps aux | grep mysql
presoft 3823 0.0 0.0 4368 816 pts/0 S+ 10:41 0:00 grep --color=auto mysql
I tried to start using using sudo /etc/init.d/mysql start
which gave the result of
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mysql
start: Job failed to start
Can any one help me to find a solution because db containing large amount of valuable data.
Thanks
Regards.