In Rails 6, how do I add "protocol" into my db configs? - mysql

I have my MySql 5.7 db running on a virtual server, whose port 3306 is forwarded to my local . I can connect using this
> mysql -h localhost --protocol=tcp -u mouser mydb_test -p
Which would fail if the params “--protocol=tcp” weren’t present. As such, I’m trying to figure out how to add “protocol” into my database.yml config for Rails 6. I discovered the below is not the way to do it
test:
adapter: mysql2
encoding: utf8
host: localhost
database: mydb_test
pool: 5
username: mouser
password: mypass
protocol: tcp
variables:
sql_mode: NO_ENGINE_SUBSTITUTION
Since I get connection errors when attempting to connect to the db.

Related

Rails no database name in connection

Trying to run a rails app in prod on Ubuntu 16.04 and installed mysql Ver 14.14 Distrib 5.7.24, Ruby 2.5.3, and using the mysql2 gem. It works fine on my Mac 10.13. My Rails app can't seem to read the DB name in Ubuntu.
Can't find the DB name:
{:adapter=>"mysql2", :encoding=>"utf8", :database=>nil, :username=>"myUser", :password=>"secret", :host=>"127.0.0.1", :port=>3306}
Then adds 127.0.0.1 as the DB name:
{:adapter=>"mysql2", :encoding=>"utf8", :database=>"127.0.0.1", :username=>"myUser", :password=>"secret", :host=>"127.0.0.1", :port=>3306}
My database.yml
production:
adapter: mysql2
encoding: utf8
database: mydb
username: myUser
password: secret
host: 127.0.0.1
port: 3306
I've been pulling my hair out as to why I can't connect to the DB in my Ubuntu server. I can log into mysql through the CLI fine with the DB user fine.
I'm also seeing the same issue on an Ubuntu box with Vagrant so thats consistent.
Any help is extremely appreciative at this time.
I have no idea but putting it in this format works. I tried everything else, different DB name, etc to no avail:
production:
url: mysql2://user:pass#localhost/myDb
Thank you for your responses.
Your database.yml should look something like this:
development:
adapter: mysql2
encoding: unicode
pool: 5
username: mysql_user
password: your_password
host: localhost_or_your_host
database: db_name
Do change your environment to match your requirements. This will work for your development mode.

How to enable passwordless access to Mysql for Rails?

I have this database config which connects to MySQL database using root without the password. How do I configure MySQL so that all database operations coming from my app will work?
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp
pool: 25
username: root
password:
host: 127.0.0.1
strict: false
possible solution
Answer to this question by chaintng
https://serverfault.com/questions/563714/allow-linux-root-user-mysql-root-access-without-password
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
along with .my.cnf configuration
$ cat ~/.my.cnf
[client]
user=root
password=''
It seems to work, but I am not sure if it is a correct solution.

Cannot connect to mysql server Error: mysqld.sock' (38)

Hi I am working on ruby on rails project. after setting up all environment for the project but when I run localhost:3000 on my web browser it gives my this error
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (38)
Can someone help me how can I solve this problem?
Check if mysql is running
mysqladmin -u root -p status
Rails by default tries to connect to MySQL using a socket file. You probably want it to connect using a TCP connection.
Check your database.yml; it should look similar to this:
development:
adapter: mysql2
encoding: utf8
reconnect: true
host: localhost
database: {database name}
pool: 5
username: {username}
password: {password}
Notice the host parameter and the missing socket parameter.

Rails Project Connection error with MySQL DB - Access Denied for root user

I get this error when running rails with mysql db. Basically it is not giving the root user access. I have no idea why this is and have been stuck with this for a while now.
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: YES)):
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack- 3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.7ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.7ms)
My Database.yml file is posted below for your reference. Im not sure how i check the password that MYSQL is automatically assigned to? Would it be my computer login password? Anyhow how do i check it. Also i cant simply type mysql on my command line i have to enter the entire path to access it. How do i change it. Most importantly i want to know how this access denied issue can be resolved. Thank you. Using mysql 5.5 on mac. x86_64 build.
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
Mysql uses the one that you've set on install. Sometimes it's empty.
Try mysql -u root. If it works - remove pass string form database yaml.
If it's not empty - https://stackoverflow.com/search?q=mysql+reset+password

cant connect from rails to mysql

im struggling to connect to my mysql service running on my local windows 7 machine- I am getting the following error when trying to rake migrations or access through the web browser-
Mysql2::Error (Can't connect to MySQL server on 'localhost' (10061)):
i have left the mysql user/pass as default - this is my yaml conf file
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
port: 3306
encoding: utf8
reconnect: false
database: events_development
pool: 5
username: root
password:
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: events_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: events_production
pool: 5
username: root
password:
host: localhost
the thing is i can login using root through mysql on the command line and also running phpmyadmin through xampp- so i have narrowed it down to a firewall issue? or permissions issues? everything is running localhost on my machine
update
i turned windows firewall off and it made no difference
Make sure you've granted localhost privileges. Info here.
i restarted the machine and restarted the servers- seemed to work
I'am a bit confused? Localost => Port (10061) ?
Maybe try to add port: 3306 everywhere.
Do you started the Server in dev env?