This project is archived and is in readonly mode.

#1459 ✓ committed
Vladimir Dobriakov

Better db:create for mysql - do not assume root user

Reported by Vladimir Dobriakov | November 24th, 2008 @ 01:33 PM | in 2.x

The current mysql adapter implementation and especially the rake db:create implementation assume, that developers use the root account for working with their mysql server. I think, it is not a good thing. The second problem is, if the database creation fails, then it fails with a wrong error message - something with 'make sure you have a matching collation' instead of 'access denied'.

How it should work:

  1. a developer puts the (non-root) credentials for the new database into the database.yml like

    development: adapter: mysql database: myapp username: myapp password: xyz1148 host: 127.0.0.1 encoding: utf8

  2. run rake db:create

  3. there are not enough rights to create the new database, so rake asks for the root password
  4. run the well-known sequence CREATE DATABASE #{db_name}; GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{user}'@'localhost' IDENTIFIED BY '#{password}' WITH GRANT OPTION;

The last sequence can be seen over and over again in all possible howtos and books. I think it is time to automate this.

If the interactive behaviour is not desired, than it can be replaced by 'failed' - 'rerun with additional parameter' loop. But probably you do not really want to provide the root password as a parameter on the command line.

The attached patch contains the implementation for the interactive scenario. Did not know, what is the common way to test such interactive stuff automatically; but at least extensively tested it manually.

Best Regards,

Vladimir Dobriakov AKA geekQ http://www.innoq.com/blog/vd

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tickets have moved to Github

The new ticket tracker is available at https://github.com/rails/rails/issues

Shared Ticket Bins

Attachments

Referenced by

Pages