replacing remote package with local directory - mysql

I'm playing around with thisenter link description here Go CRUD api app. The READ.me advises that mysql needs to be configured in config/dbconn.go. In the source code, mysql is configured to use port 3306. I cloned the source code and changed the config to use port 8889, which MAMP mysql requires me to use for my own scripts (the only mysql I have on my system is through MAMP).
dbUserName := "root"
dbPass := "root"
dbIp := "127.0.0.1"
dbPortNo := 8889
When I ran cloned version of the app and tried to visit one of the routes, I got this error message
Create tables failed dial tcp 127.0.0.1:3306: connection refused
exit status 1
So I'm assuming that it's trying to connect on the port through 3306, and when I look in the util.go file of the project, I see that it's importing the config from the remote repo, rather (I'm assuming) than using the config file in the local repo that I changed to use the mysql settings for MAMP
util.go
import (
"github.com/mantishK/gonotevanilla/config"
)
My question is, if the problem is as I think it is, how do I tell util.go to use the database config file at /config/dbconn.go rather than the file that's in the remote repo.
I tried to using
"config"
and
"/config"
and I got the same error

Related

socat throw error while trying to connect external mysql

I try to connect 2 docker containers to each other via socat.
Inside of the web container, I'll use socat to bind the external mysql-container to Port 3306.
I do use this command line:
socat TCP:$MYSQL_CONTAINER_IP:$MYSQL_CONTAINER_PORT,fork,reuseaddr,unlink-early,user=root,group=root,mode=777 UNIX-LISTEN:$MY_SOCKET &
While $MYSQL_CONTAINER_IP = 172.17.0.2
and $MYSQL_CONTAINER_PORT = 3306
$MY_SOCKET is set via:
MY_SOCKET=$(mysql_config --socket)
and result in /var/run/mysqld/mysqld.sock
But if I run this command, I got this:
2022/05/29 06:43:54 socat[10267] E bind(6, {AF=1 "/var/run/mysqld/mysqld.sock"}, 29): No such file or directory
The Web-Docker-Container is debian:buster (Debian buster [10]),
The MySql Container is Debian wheezy:latest
Any Idea, why I got the above noticed error-message?
The error message sounds like directory /var/run/mysqld/ does not exist in the environment where Socat is run. I'd recommend to check this.
However, the Socat command line you constructed, with the fork option on the TCP address, will try every second to establish another connection to the MySQL server, and from the second connection (and sub process) on the UNIX bind will fail.
For typical forwarder uses, you should have the listener with fork as the first address, and the connector (here TCP:) as second address.

Unable to connect to remote mysql server using unixodbc, libmyodbc

I'm a little green at this, and I hope the issue I'm having is a simple one...edit: new information at bottom
I need to make a connection to a remote mysql (Amazon RDS) database.
After following a few tutorials, I have unixodbc and libmyodbc installed and configured on the client, but when I try to connect via isql, I get the error
[08S01][unixODBC][MySQL][ODBC 5.1 Driver]Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[ISQL]ERROR: Could not SQLConnect
The most confusing part about this error is that I'm not trying to connect to a local database, but rather to a remote one. I do not have a mysql.sock file on the client...this isn't the issue though is it?
I'm sensing a configuration error but I'm just not sure what it could be.
If I run odbcinst -j then the output is:
DRIVERS............: /etc/unixODBC/odbcinst.ini
SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini
The content of /etc/unixODBC/odbcinst.ini is:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib64/libmyodbc5.so
Setup = /usr/lib64/unixODBC/libodbcmyS.so
UsageCount = 5
[MySQL ODBC 515 Driver]
Description = ODBC 5.515 for MySQL
DRIVER = /usr/lib64/libmyodbc5-5.1.5.so
SETUP = /usr/lib64/unixODBC/libodbcmyS.so
UsageCount = 3
Please note that I had to make up this configuration myself, I did a find for libmyodbc* and found these two .so files, thus set up a driver for each of them. A search for libodbcmyS* yields:
/usr/lib64/unixODBC/libodbcmyS.so.1
/usr/lib64/unixODBC/libodbcmyS.so
/usr/lib64/unixODBC/libodbcmyS.so.1.0.0
So, I don't know what else that configuration could be.
The content of /etc/unixODBC/odbc.ini is:
[target_db]
Driver = MySQL
Server = [servername.com]
Port = 3306
Database = [databasename]
Option = 2
User = [username]
Password = [password]
I've tried different options in "Driver", changing it from MySQL, to MySQL ODBC 515 Driver, to the path to the .so file (eg: /usr/lib64/libmyodbc5.so) and all yield the same result.
I'm running:
odbcinst -i -d -f /etc/unixODBC/odbcinst.ini
Followed by:
odbcinst -i -s -l -f /etc/unixODBC/odbc.ini
Followed by:
odbcinst -s -q
Which prints out the name of my connection, ie [target_db]
Then, I try the connect:
isql -v target_db user password
or just
isql -v target_db
and get the error shown above.
Anyone happen to know what I'm doing wrong here? Thanks a bunch-
EDIT:
Wanted to mention that I'm able to connect to the database from this server using the mysql command line tools.
I installed a local mysql database, and I'm able to connect to this using isql. It seems to be ignoring my odbc.ini file entirely, i have to enter a name with the command, ie isql -v test-database, but it still tries to connect to localhost despite my settings.
I feel as though I've tried everything but will keep at it and will post if i find a solution.
You could try to connect using the ip of your server instead of the dns entry on the "Server" line of odbc.ini.. Have you verified the driver is installed with phpinfo()?
Try to set the environment variable ODBCINI with the path of your odbc.ini file.
Keep in mind that the odbc.ini file you point to must be "write-accessible" by the user that is running the program (i.e. the user must have permissions to write in this file).
chmod g+w .odbc.ini did it for me since we run the DB with ORACLE-Start and the crs-User seems to be in charge

How to special the mysql sock path in clsql?

When I connected to mysql using clsql,the following error occurred
While trying to connect to database localhost:3306/root/
using database-type MYSQL:
Error 2002 / Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2)
has occurred.
[Condition of type SQL-CONNECTION-ERROR]
My mysql.sock path is "/home/myhome/var/run/mysql/mysql.sock",how
can I change the default sock path in clsql?
Here is my code, (SBCL 1.0.50 ,mysql 5.0,clsql-20130128-git)
(asdf:operate 'asdf:load-op 'clsql)
(in-package #:clsql-user)
(clsql:connect '("localhost" "username" "password" "dbname" 3306 ) :database-type :mysql)"
I would suggest creating a ~/.my.cnf or (if you have root access) /etc/my.cnf file and including a client setting for the socket, libmysqlclient might pick this up.
Failing that (or if you don't want to make a global change) the doc suggests you can specify a list of MySQL options as a separate assoc list http://clsql.b9.com/manual/connect.html which get passed into mysql_options()
Funny,the answer is that change the host from "localhost" to "127.0.0.1"

Trouble tunneling my local Wordpress install to the mysql database on appfog

I've set up a wordpress install on appfog (using rackspace), and cloned the install to my local machine for development. I know the install works (using MAMP) because I created a local mysql database and changed wp-config.php to point to it. However, I want to develop without having to change wp-config.php every time I commit. After doing some research, it seems like the Appfog service Caldecott lets me tunnel into the mysql database on the server, using af tunnel. Unfortunately, I'm having issues with getting it working. Even if I change my MAMP mysql port to something like 8889, and tunnel mysql through port 3306, it looks like it's connected but I still get "Error establishing a database connection" when loading my localhost Wordpress. When I quit the mysql monitor (using ctrl+x, ctrl+c), I get a message stating "Error: 'mysql' execution failed; is it in your $PATH?'. Originally, no, it wasn't, but I've fixed my PATH variable on my local machine so that when I go to Terminal and just type mysql, it loads up.
So I guess my question is 2 parts:
1.)Am I going with the right approach for Wordpress development on my local machine
and
2.)If so, why is the tunnel not working?
One way to deal with this is to mimic the VCAP_SERVICES environment variable on your local system with your local database settings. This would allow you to use the same custom AppFog wp-config.php file which looks at VCAP_SERVICES to get its db creds.
export VCAP_SERVICES='{"mysql-5.1": [{"credentials": {
"hostname": "localhost",
"port": 3306,
"password": "root",
"name": "LOCAL_DATABASE_NAME",
"user": "root"}}]}'
EDIT: You will need to restart the Apache server in MAMP after setting this env var. (Thanks Dex)
This will eliminate the need to point your development code at your production database.
simply test for whether vcap_services are available. if they are, use one config. if they arent, use a different config.
here is an example of my local + appfog development website configuration file.
if(getenv("VCAP_SERVICES")){
//if in webserver
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
$username = $mysql_config["username"];
$password = $mysql_config["password"];
$hostname = $mysql_config["hostname"];
$port = $mysql_config["port"];
$db = $mysql_config["name"];
define("DB_SERVER", "$hostname");
define("DB_USER", "$username");//enter your database username
define("DB_PASS", "$password");//databse password
define("DB_NAME", "$db");//database name
} else {
//if in local development
define("DB_SERVER", "localhost");
define("DB_USER", "website");//enter your database username
define("DB_PASS", "dfgdfgdf");//databse password
define("DB_NAME", "fgdf_web");//database name
}
also, you can use .afignore same way you'd use .gitignore to ignore some files from the af update feature. u can update once with appropriate config, then add afignore, then it will never get updated again.
Here is a quick and very dirty script to automate the process based on Tim Santeford's answer. Be sure to change the LOCAL_DATABASE_NAME
#!/bin/bash
export VCAP_SERVICES='{"mysql-5.1": [{"credentials": {"hostname": "localhost", "port": 8889, "password": "root", "name": "LOCAL_DATABASE_NAME", "user": "root"}}]}'
/Applications/MAMP/Library/bin/httpd -k stop
sleep 3
/Applications/MAMP/Library/bin/httpd -k start

Rake db:create continues to use /tmp/mysql.sock despite my.cnf settings

I'm on a Mac and used brew to install an updated MySQL. In an effort to streamline my local database creation, I took the password off my local root user (I know, I know), and after creating a new Rails app (rails new myapp -d mysql), should just be able to run rake db:create, right?
However, despite having /etc/my.cnf set to define the standard mysql.sock location...
[mysqld]
socket=/usr/local/var/mysql/mysql.sock
[client]
socket=/usr/local/var/mysql/mysql.sock
... Rails still won't use the newly defined mysql.sock file on a rake db:create:
rake db:create
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"delayed_jobs_development", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost"}, charset: , collation:
Running mysqladmin variables lists the correct socket file location, as does mysql --help. I've restarted the MySQL server and even recreated the Rails app.
So my question: What else could be defaulting the socket file to /tmp/mysql.sock, or is there an alternate, preferably global, config file where I could specify its location that the rake task will honor? Could the rake task be calling a different commandline MySQL tool that uses a different config file?
Obviously, I could either create a symlink from the /tmp location to my real location, or edit my database.yml file to refer to it. I understand how to get Rails to talk to the DB server correctly, but the point is to have the proper defaults set up once, so any future Rails app I create locally is good to go without extra edits (/tmp/mysql.sock gets cleared on reboot).
In fact, I'm not even sure why it's trying to connect via the socket file at all, since my database.yml file tells it to use the hostname:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp_development
pool: 5
username: root
password:
host: localhost
As the MySQL documentation says, /tmp/mysql.sock is the default location for the socket file. This is also what rails defaults to (more below).
As you mentioned, you can always set the socket (the one you configured and that is returned by mysqladmin variables) explicitly in your database.yml file:
socket: /usr/local/var/mysql/mysql.sock
I think the connection is made via the socket file as you set host: localhost. If you change that to 127.0.0.1, the connection should by made over TCP/IP.
I found rather old information (a really old version of the mysql adapter and a blog entry from 2007) which implies that the MYSQL_UNIX_ADDR environment variable is used in resolving the socket. Also see this comment on GitHub by the developer of Ruby/MySQL, in which he says to set the MYSQL_UNIX_PORT variable instead. A third env variable is MYSQL_SOCKET mentioned in the source of the Ruby/MySQL connector.
export MYSQL_UNIX_ADDR=/usr/local/var/mysql/mysql.sock
export MYSQL_UNIX_PORT=/usr/local/var/mysql/mysql.sock
export MYSQL_SOCKET=/usr/local/var/mysql/mysql.sock
I do not know if these variables get evaluated somewhere along the way. Still, you could try them out.
Right now, rails mysql_adapter.rb says that the configured socket is used and that it defaults to /tmp/mysql.sock (set in app_generator.rb). No other locations seem to get checked. I did not found anything else in the default Ruby/MySQL adapter used by rails.
So basically – without being an expert on this topic – I don't think there is a way to set a global default location for the MySQL socket file that gets evaluated by rails or the used default adapter.