Im trying to use MySQL as a database for an application to which I updated the default database.yml file to
development:
adapter: mysql
encoding: utf8
reconnect: false
database: ***_development
pool: 5
username: root
password: ******
host: localhost
test:
adapter: mysql
encoding: utf8
reconnect: false
database: ***_test
pool: 5
username: root
password: ******
host: localhost
production:
adapter: mysql
encoding: utf8
reconnect: false
database: ***_production
pool: 5
username: root
password: ******
host: localhost
`
But I dont see any .sql file being generated after trying to create tables from the console. Im a noob in Ruby on rails any help would be appreciated. Thank you.
It won't be in your rails directory. You need MySQL installed on your computer and you need to create the databases in mysql.
Install mysql: http://dev.mysql.com/doc/refman/5.1/en/installing.html
To access mysql through the command line:
$ mysql
or if you have a mysql root user:
$ mysql -u root -p
And enter your root mysql user password. Once you are in mysql:
mysql> CREATE DATABASE db_name;
mysql> GRANT ALL PRIVILEGES ON db_name.*
mysql> TO 'username'#'localhost'
mysql> IDENTIFIED BY 'password';
Obviously replace db_name, username and password accordingly.
Related
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.
I have a problem connecting to DB from my rails app.
I have provided the database.yml file with credentials:
development: &development
adapter: mysql2
encoding: utf8
database: myapp_dev
pool: 5
username: root
password: passoword
test:
<<: *development
database: myapp_test
production:
<<: *development
database: myapp_prod
staging:
<<: *development
database: myapp_staging
But when I try run the app it gives me the following error:
Access denied for user 'root'#'localhost' (using password: NO)
using mysql -u root -p with same credentials I can access my db without issues. can someone tell me what could be a problem here?
EDIT:
I've changed the user from root to some other user but it still gives me the same error. so apparently it uses some other credentials to connect to db.
I ran into the same issue. It turns out it was a mistake in my database.yml file. Here is what my database.yml file looked like:
production:
adapter: mysql2
encoding: utf8
database: my_db
username: my_db_user
password: !strong_password
host: localhost
port: 3306
pool: 5
timeout: 5000
The ! character at the beginning of the password is not valid YAML markup (for at least what I was trying to achieve). Wrapping quotes ('') around the password fixes the issue. Here is the updated database.yml file:
production:
adapter: mysql2
encoding: utf8
database: my_db
username: my_db_user
password: '!strong_password'
host: localhost
port: 3306
pool: 5
timeout: 5000
Try the following code, if it works we can go forward
Comment all the previous code in database.yml and paste the following
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp_dev
pool: 5
username: root
password: passoword
host: localhost
I am able to open the mySQL command line doing the following steps:
depot>mysql -u root
mysql>CREATE DATABASE depot_production DEFAULT CHARACTER SET utf8;
mysql>GRANT ALL PRIVILEGES ON depot_production.* TO 'gotqn' IDENTIFIED BY 'mypass';
mysql>EXIT;
then changing my config/database.yml
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_production
pool: 5
username: gotqn
password: mypass
host: localhost
and final typing:
gotqn:~/Aptana Projects/depot$mysql depot_production
gives me:
ERROR 1045 (28000): Access denied for user 'gotqn'#'localhost' (using
password: NO)
I've supposed that I should specified a password but typing:
gotqn:~/Aptana Projects/depot$mysql depot_production mypass
just shows me the some variables information.
I am using:
Rails 3.2.8
mysql Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (x86_64) using
readline 6.2
Ubuntu LTS 12.04
Configuration file config/database.yml is for Ruby, not for mysql command line tool. For command line tool use correct syntax:
mysql --user=user_name --password=your_password db_name
by default it uses your current logged in user if --user=user_name is omited.
In database.yml use username as root:
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_production
pool: 5
username: root
password:
host: localhost
Create the user in mysql as #'localhost'
mysql>GRANT ALL PRIVILEGES ON depot_production.* TO 'gotqn'#'localhost' IDENTIFIED BY 'mypass';
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
I'm creating my first ROR application.
Details:
creating new app ->
rails new simple_cms -d mysql
creating a controller and a corresponding view -->
rails generate controller demo index
Then when after i started the rails server, the http://localhost:3000 page works perfectly fine. but when i try to go to the page that I just created, http://localhost:3000/demo/index, it spurts out a MYSQL error:
Access denied for user 'root'#'localhost' (using password: NO)
At first, I think it's just a database connection problem, so I've gone through the MYSQL interface and create a new database called: simple_cms_development
and I have also made a corresponding user: simple_cms
with granted privileges.
and lastly, I have configured the database.yml file to fit the details:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: simple_cms
password: developer
host: localhost
But still, it spits out the same mysql problem:
Access denied for user 'root'#'localhost' (using password: NO)
Please. to anyone who knows how to use mysql as a database for rails app..A help would be really appreciated. Thank you so much!
UPDATE: This is all what's inside on the database.yml file
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: root
password: developer
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: simple_cms_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_production
pool: 5
username: root
password:
host: localhost
I found that you need to add the following line to config/database.yml:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
host: your_host # <----- normally localhost
database: the_db_I_made
pool: 5
username: the_user_I_made
password: the_password
socket: /var/lib/mysql/mysql.sock
Only reason that can cause your issue is that you are loading your server with different environment. I think that in your case you are loading your server under production mode.