0

I am trying to do rake db:create in one of my rails app. I get the error that says

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"new-db", "pool"=>5, "username"=>"root", "password"=>"password"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)

This is what my database.yml looks like

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: new-db
  pool: 5
  username: root
  password: password

I tried adding host:localhost in above code, It didn't work.

Also, when I am trying to login to mysql with mysql -u root -password, I am getting

 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Can someone please help here..

Suraj
  • 2,423
  • 12
  • 39
  • 75
  • Possible duplicate of [rake db:create - collation issues](http://stackoverflow.com/questions/1363772/rake-dbcreate-collation-issues) – Ilya May 16 '16 at 09:16
  • @Ilya It didn't help me... – Suraj May 16 '16 at 09:20
  • which os are you using? – uzaif May 16 '16 at 09:21
  • ubuntu 14.04 is the operating system – Suraj May 16 '16 at 09:23
  • Your `mysql.sock` file is corrupted. I guess this will do the trick: http://stackoverflow.com/questions/1363772/rake-dbcreate-collation-issues#3757874 – Emu May 16 '16 at 09:26
  • @Emu error is regarding character-set not regarding socket – uzaif May 16 '16 at 09:27
  • I get different set of errors after this, I tried that .. `dpkg: error processing package mysql-server-5.5 (--configure): dpkg: dependency problems prevent configuration of mysql-server: mysql-server depends on mysql-server-5.5; however: Package mysql-server-5.5 is not configured yet.dpkg: error processing package mysql-server (--configure): dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup error from a previous failure. E: Sub-process /usr/bin/dpkg returned an error code (1) ` – Suraj May 16 '16 at 09:28
  • remove `encoding` from yml – uzaif May 16 '16 at 09:28
  • 1
    @uzaif, read the question first. He cannot access mysql manually because of the socket, how do you think the project can access that? – Emu May 16 '16 at 09:29
  • I get same above error by removing `encoding` – Suraj May 16 '16 at 09:29
  • hate it the way people mark things duplicate even when I am saying that didn't answer the question. – Suraj May 16 '16 at 09:32
  • @Suraj i think your mysql is not running – Vishal JAIN May 16 '16 at 09:45
  • @VishalJAIN `sudo service mysql status` This is what I get `mysql start/post-start, process 20721 post-start process 20722 ` – Suraj May 16 '16 at 09:46
  • Please run `sudo install mysql-server-5.5` and show us the output. – Aleksei Matiushkin May 16 '16 at 09:54
  • [here's](http://pastebin.com/XUwX2eB9) the output – Suraj May 16 '16 at 09:56
  • Have you installed mysql-server ? if not - `sudo apt-get install mysql-server` – dr. strange May 16 '16 at 09:57
  • Obviously I have installed `mysql-server` @Amit – Suraj May 16 '16 at 09:58
  • @Suraj try to reboot a machine. It looks like you have two `apt` processes running. – Aleksei Matiushkin May 16 '16 at 10:04
  • please have look to this one [http://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq] – dr. strange May 16 '16 at 10:05
  • @mudasobwa rebooted. trying again – Suraj May 16 '16 at 10:14
  • `E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? ` Got this. the whole distro is upset it seems :-s – Suraj May 16 '16 at 10:17
  • `sudo rm -rf /var/lib/dpkg/lock` – Aleksei Matiushkin May 16 '16 at 10:23
  • `gradle-2.10 mariadb-common Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. 2 not fully installed or removed. E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable) E: Unable to lock directory /var/cache/apt/archives/ ` After doing the above command – Suraj May 16 '16 at 10:24
  • `sudo rm -rf /var/cache/apt/archives/lock` and retry with `sudo apt-get update`. – Aleksei Matiushkin May 16 '16 at 10:31
  • [this](http://pastebin.com/7XT6Vkq5) error now – Suraj May 16 '16 at 10:38
  • Just `sudo rm -rf WHATEVER_FILE_IS_REPORTED_AS_LOCKED`. This should [hopefully] help. – Aleksei Matiushkin May 16 '16 at 10:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112047/discussion-between-suraj-and-mudasobwa). – Suraj May 16 '16 at 10:53

1 Answers1

-1

add tab space before each line except first line EX. below

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: new-db
  pool: 5
  username: root
  password: password
dr. strange
  • 665
  • 7
  • 22