MySQL: create user and root password

Vladimir Mihailenco avatarVladimir Mihailenco created an issue

What's done:

  • mysql_create_user() command
  • ability to specify root and non-root password
  • grant permissions to user while creating DB

Changeset: https://bitbucket.org/vladimir_webdev/django-fab-deploy/changeset/479580b5f9ce

I have to admit that it is totally untested. I will make some tests later (I got some high-priority tasks), but if you already see any problems with this code please let me know.

Comments (9)

  1. Mikhail Korobov

    This is a long-awaited feature, really)

    DB_ROOT_PASSWORD is set to DB_PASSWORD by default => it is not None by default => _get_root_password() wouldn't ever ask user's password. I think DB_ROOT_PASSWORD should set to DB_PASSWORD by update_env only if DB_USER is 'root', this will be convenient and backwards-compatible.

  2. Vladimir Mihailenco

    I have successfully deployed Django 1.3 project to Ubuntu 10.10, using my branch: https://bitbucket.org/vladimir_webdev/django-fab-deploy/changeset/2601e42f0778 (I am working on default branch, because I need to specify my repo in PIP requirements). Some notes:

    - db user creation looks unneeded, because MySQL automatically creates user while executing GRANT PERMISSION command (mysql Ver 14.14 Distrib 5.1.49);

    - added --force option to git commands, so git does not refuse to perform command (I use long options (--force vs -f) everywhere and I hope this is a good practise :); git config is removed;

    - added new Django collectstatic command; should we call this command for every Django 1.3 project during deployment?

  3. Mikhail Korobov

    Hi Vladimir,

    I still can't found a time to merge your changes. This is non-trivial merge, test project №2 should be updated with new setup (it should e.g. use non-default SUDO_USER), tests and docs for new commands and options should be added and setup should be tested with all Debians as well as Ubuntu. I hope I'll find some time soon :)

    - db user creation looks unneeded, because MySQL automatically creates user while executing GRANT PERMISSION command (mysql Ver 14.14 Distrib 5.1.49);

    Hm, very interesting. Do you know if it works with Debian Lenny (mysql 5.0)?

    - added new Django collectstatic command; should we call this command for every Django 1.3 project during deployment?

    No, we shouldn't. Not every django 1.3 project will use staticfiles, and we will have to determine user's django version in order to support this feature (btw, django-fab-deploy doesn't even require django to be installed on local machine now).

    I also like that collectstatic is used in customization example: http://packages.python.org/django-fab-deploy/customization.html#an-example-of-fab-push-customization . Django 1.3 users can find an example in docs and get used to django-fab-deploy customization through implementing their custom 'push' command.

    I'm not opposed to making collectstatic an argument for 'push' command (like syncdb or migrate) though. But we shouldn't call it by default - it can lead to data loss and is not needed in many cases.

    Introducing collectstatic command: +1.

  4. Vladimir Mihailenco

    Hm, very interesting. Do you know if it works with Debian Lenny (mysql 5.0)?

    Don't know really, I guess it depends on setting this option: http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_no_auto_create_user , but I think we can't rely on it. Anyway for now DB operation should be done by hands and this is not an issue.

    django-fab-deploy doesn't even require django to be installed on local machine now

    Hm, I think Django is available as we deploy Django project :) django.get_version() and hasattr(settings, 'STATIC_URL') can do their job also, but I don't insist on this.

  5. Mikhail Korobov

    Hi Vladimir,

    I've merged your changes with small modifications. Most important, git-related changes are reverted because they cause tests to fail (this should be separate ticket anyway), and UTF8 defaults for database creation are restored - is there any reason to remove them?

    Existing tests are passing now. I'll make a release as soon as we write tests and docs for the new features.

    Thanks for your work on this!

  6. Vladimir Mihailenco

    As for git, I will check what I missed. I thought that --force option should be enough.

    As for UTF-8... I removed it because typically I set encoding for entire DB (mysql) and then all new DBs are created with that default encoding. But I guess explicit setting UTF-8 in fab-deploy is ok too.

  7. Mikhail Korobov

    Default DB encoding is not utf8 on default mysql installation (at least on Lenny) so it was necessary in my case.

    The git error (Squeeze):

    run: git init
    [foo2@127.0.0.1:2222] out: Initialized empty Git repository in /home/foo2/src/foo2/.git/
    [foo2@127.0.0.1:2222] out: 
    [localhost] local: git push --force ssh://foo2@127.0.0.1:2222/~foo2/src/foo2/ master
    Counting objects: 22, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (15/15), done.
    Writing objects: 100% (22/22), 4.30 KiB, done.
    Total 22 (delta 0), reused 0 (delta 0)
    remote: error: refusing to update checked out branch: refs/heads/master
    remote: error: By default, updating the current branch in a non-bare repository
    remote: error: is denied, because it will make the index and work tree inconsistent
    remote: error: with what you pushed, and will require 'git reset --hard' to match
    remote: error: the work tree to HEAD.
    remote: error: 
    remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
    remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
    remote: error: its current branch; however, this is not recommended unless you
    remote: error: arranged to update its work tree to match what you pushed in some
    remote: error: other way.
    remote: error: 
    remote: error: To squelch this message and still keep the default behaviour, set
    remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
    To ssh://foo2@127.0.0.1:2222/~foo2/src/foo2/
     ! [remote rejected] master -> master (branch is currently checked out)
    error: failed to push some refs to 'ssh://foo2@127.0.0.1:2222/~foo2/src/foo2/'
    
  8. Mikhail Korobov

    There are tests and docs for new features. I've also added mysql user creation and fixed a couple of issues introduced during merge. Hope this can be considered resolved now. Thanks Vladimir for working on this!

  9. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.