How do I connect to MySQL from Ruby? - mysql

I have MySQL installed in the /usr/local/bin/. I need to be able to connect to the MySQL database, however, the mySQL gem cannot connect to my database, and it seems that it is looking for the database in the /opt folder.
Can anyone suggest how I can fix this?

Some thoughts about this:
Have you checked if MySQL is actually running? In most linux environments this can be done on the command line by executing "/etc/init.d/mysql status" or simply connecting to the database with the command line client.
I think your configuration should point to "localhost" when running on the same machine and is then using either sockets or tcp connections to connect to the database, so the /opt folder message you posted seems weird.
Please provide more information.

Related

Remotely Accessing MySQL on Mac Mini/Time Capsule

I'm currently trying to run an application on a server but my customer is very 'picky' about their data and wish to store the database on their own internal office server. I've installed MySQL and can get the application to run locally but for a few specific reasons the application needs to run else where.
I basically can't get access to MySQL from a different location. I think my main stumbling block is port forwarding to the correct location. MySQL is installed on a mac mini with local IP address 192.168.1.242 and the router/modem is an Apple Time Capsule. I've tried looking at tutorials but they all have options that I don't have access to. I've attached a screenshot of the options I have access to and the settings I've tried so far.
Other information possibly needed is:
I need to connect from PHP
I've set a user up within MySQL with a wildcard (%)
I'm testing it using the following: command on my local machine in CMD: mysql -u username -h remote_ip_address -p
I get the following error: ERROR 2003 (HY000): Can't connect to MySQL server on 'REMOTE_IP_ADDRESS' (10061)
Firewall is turned off completely on the Mac Mini
There is nothing in the my.cnf file
OS is Sierra
That's all I can think of at the moment but any advice would be greatly appreciated and any more information required can be provided.
PS. evidently I'm not very good with MAC machines/networks
For anyone that reads this I had a very specific issue. I installed MySQL using homebrew. Homebrew binds MySQL to 127.0.0.1 therefore will only allow connections to MySQL from the same machine no matter what you try to do. To fix it I've had to edit /usr/local/Cellar/mysql//homebrew.mxcl.mysql.plist and replace --bind-address=127.0.0.1 with bind-address=*.
MySQL has an internal firewall of users/IPs. Even if you can connect locally, you might not have permission remotely:
Try this as root user on the MySQL server (locally first!)
GRANT ALL ON <db>.* TO '<user>'#'<remoteIP>' IDENTIFIED BY '<password>';
Where
<db> is the name of the DB
<user> is name under which you connect
<remoteIP> is your external office IP FROM which you are trying to connect
<password> should be self-explanatory!
This will explain the options better

problems connecting to port 3306 mysql workbench with XAMPP

I'm trying to learn the apache / mysql / php stack bundled with XAMPP. I can't connect to the MySQL server using the MySQL workbench:
Your connection attempt failed for user 'root' from your host to server at localhost:3306: Can't connect to MySQL server on '127.0.0.1' (61)
Thinking it's a port problem, I check the port directly in Terminal with the command telnet 3306:
telnet: connect to address 127.0.0.1: Connection refused
Obviously the problem isn't with the Workbench, but something to do with the port connection itself.
I'm using:
OS 10.8 Mountain Lion
XAMPP 1.7.3
MySQL workbench 5.2.47
Sorry all, I'm posting my own question and answer. I had this problem and it nearly destroyed me because I could not find the correct answer anywhere on the interwebz. I finally overcame it, and wanted to post my findings in case it helps another befuddled traveler.
It turns out when you install XAMPP and choose to run the security routines, it automatically turns on a setting in the MySQL preferences to block connections on port 3306 from localhost. To fix this, open my.cnf in the xampp folder xamppfiles/etc. Look for the setting "skip-networking" which tells mySQL to block the port 3306. Comment this out by adding a pound sign so it is "#skip-networking". Now, the telnet command should work, and you should be able to use the Workbench.
Hope this is helpful for somebody!If it fixes your problem, give me a shout at #mrcheeks3185.
I faced same problem but I solved it.
I changed the MySQL workbench port to 3307 in the file below
C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
and keep the default port 3306 for XAMPP
for mac you should create only a user with password and grant access(in my case a I use root with password) and turn on ip address and use that address to connect with a client like navcat or workbench I use XAMPP 7.3
ip address network given by XAMPP
connection config in navcat
test connection
I found that file after mount the image disk created for xampp, there you can find new_disc_mounted/etc/my.cnf
If you do not have my.cnf you can first go to xampp->mysql->bin->my.ini, copy
the contents of the file, next create my.cnf (in the bin folder) and paste the content to the file you just created.
This works for me. I had the same problem. Now I can use both Xampp and Workbench on one PC.
There is an issue: when you start workbench you get some warning that some features may not work properly since database is not fully compatible.
If changing ports won't work. What I did, I just make sure both XAMPP and MySQL Workbench don't start the server at the same time. Just go to MySQL Workbench, Select Server > Startup/Shutdown > Shutdown.
its due to different version of xampp, open log file and check last status of mysql there is showing error find it or remark/change it
Actually XAMPP and MySQL workBench might be using same port an are conflicting "3306" in so you are getting that error
Please try changing the workBench's default port number to other number and try again

ODBC 3.51 Driver Can't connect to MySQL server on localhost (10061)

Exactly what the title said; I'm trying to configure an ODBC connection for MySQL 5.0, but upon clicking Test Data Source, it returns the above error.
I'm pretty sure most of you have seen this question before, and I did do some research before thinking about posting this, but so far, none of what I found and tried were able to help.
I'm using MySQL 5.0, running on Windows 7 32-bit. I can browse the database fine with the MySQL Query browser which means (I'm assuming) that the username and password are fine.
There is a 'MySQL 5 - Started' under Services. I named it that way because I had installed an older version of MySQL (3, iirc) for a project. Since I don't need it yet, I disabled it (it's not running).
Here's what I tried:
Firewalls were disabled to begin with.
Replacing the 'localhost' with '127.0.0.1' (Didn't work)
Going into Command prompt, cd to C:\Program Files\MySQL\MySQL Server 5.0\bin, and executing mysqld-nt (I have no idea what that is for, but it didn't do anything)
Running 'Telnet localhost 3306' in the Command Prompt returns 'Could not open connection to the host , on port 3306: Connect failed.
Stopping the service, going into C:\Program Files\MySQL\MySQL Server 5.0\data, deleting ib_logfile0, ib_logfile1, and ibdata1, and then restarting the service (Didn't work).
I'm assuming here that it might have something to do with the port 3306, as typing netstat -a in the command prompt gets me a list with no 3306 in it (as far as my eye can tell), so I'm not really sure how to proceed (port forwarding? Don't know how to do that).
Any help would be much appreciated. Thanks.
I had same problem before, please check your Mysql Service and make Startup Type as Automatic and Restart.
If you really tried most of the solutions and still didn't succeed, try to delete or rename(to any name) the ib_logfile0 and ib_logfile1 in the data folder of mysql. For me the path is wamp/bin/mysql/mysql5.6.12/data. because i am using wamp. And run the mysqld service. May it helps you. Good luck.
MySQL server might got stopped.Please check the status of MySQL server in the services if it got stopped please start the services and try to connect again.
You said
Replacing the 'localhost' with '127.0.0.1' (Didn't work)
For my network (in mysqld.cnf) replacing 127.0.0.1 with 0.0.0.0 just worked... connected.

Getting Path to MySQL on Apache running on Windows

I've set up an Apache 2.2 and PHP 5.3 server on my Windows 7 machine. However, phpinfo() tells me that I have MySQL installed as well, but I had no clue I do. I'm having trouble finding the installation, so how can I find the path to MySQL? I know how to do so with Linux (whereis MYSQL), but what do I do with Windows?
If you didn't setup MySQL explicitly, and you didn't install a complete WAMP installation, you don't have MySQL. PHP just checks if the MySQL library is installed. If you try to connect, it will probably fail.
I would check under C:\Program Files\MySql or under c:\MySql
Also, MySql typically is configured to run on port 3306; so I would
check whether you have this port open on your local computer. How?
Just telnet to port 3306 on localhost and see if you can connect. If
you can, most likely MySQL is running on your PC and you should be
able to connect to it.
Read the MySQL Documentation regarding this topic.

Not your usual MySQL4 + ODBC connection issue

I've got a problem with ODBC that has me stumped, and I can't find an answer anywhere that addresses my problem. Short version: I can't connect to my MySQL4 installation on Ubuntu Jaunty from my WinXP ODBC System DNS, even tho I can connect just fine using the command line client both on that particular machine and others.
Huge amount of details starts here!
I have a standard MySQL5 install on Ubuntu Jaunty 9.04. I manually installed MySQL4 from precompiled binaries in /usr/local/mysql4. Here's the startup command:
/usr/local/mysql4/bin/mysqld_safe --user=mysql4 --port=3307 --socket=/var/run/mysql4d/mysql4d.sock --basedir='/usr/share/mysql4/' --datadir='/var/lib/mysql4/' --log-error='/var/log/mysql4.err' --log='/var/log/mysql4.log' --language='/usr/local/mysql-standard-4.1.22-pc-linux-gnu-i686-glibc23/share/mysql/english' &
This seems to work quite well. I have no problems connecting using the mysql client from either localhost or from a remote machine over TCP/IP:
mysql -u inContact -h myhost.com --password='blah' --port=3307
On this same server, I have virtualbox running XP Pro. I can also connect no probs using mysql on the command line from it. However, using the same settings for the ODBC system DSN don't work. I get the message "Host 'myhost.com' is not allowed to connect to this MySQL server".
The only message I'm seeing about it is in mysql4.log:
091124 10:56:50 5 Connect inContact#myhost.com on inContact
Anyone have some insight? I'm totally at a loss here...
You need to give permissions to the user you want to connect with. Use the GRANT statement.
Should have mentioned that privs were GRANTed already, sorry!
The issue turned out to be corrupted mysql.user and mysql.db tables. Repairing the tables wasn't successful, so I tried dropping most records and then repairing the table (which worked) and then re-added the users and GRANTs. Worked after that :)