Results 1 to 7 of 7

Thread: Delete MySQL User Shell Script

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    75
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    6

    Default Delete MySQL User Shell Script

    Good Morning,

    sorry for my frequently question, but how I can delete an sql users from shell scripts in an one command?

    THanks for the support

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,515
    Thanks
    17
    Thanked 814 Times in 511 Posts
    Rep Power
    10

    Default

    There is no need to write a shell script. All you have to do is run one command at mysql> prompt:
    Code:
    DROP USER userName;
    However, DROP USER will not automatically delete any database objects that the user created. This applies to tables, views, stored routines, and triggers etc all.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Member
    Join Date
    Jul 2009
    Posts
    75
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    6

    Default

    yes but i want insert the command into bash scripts because it is an part of an multiple operation

    if i want make this into only line i can use this?

    Code:
    mysql -uroot -ppassword > DROP USER users;
    I have tryed but it seems not work... where i wrong?
    Last edited by nixcraft; 2nd October 2009 at 06:24 PM. Reason: code tags

  4. #4
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,515
    Thanks
    17
    Thanked 814 Times in 511 Posts
    Rep Power
    10

    Default

    Try
    Code:
    #!/bin/bash
    ...
    ...
    # set username
    userName="foo"
    mysql -u username -p'Password' -e "DROP USER $userName;"
    ...
    ..
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  5. #5
    Member
    Join Date
    Jul 2009
    Posts
    75
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    6

    Default

    Hi,

    i have tryed but this is the error


    Code:
    ERROR 1396 (HY000) at line 1: Operation DROP USER failed for 'foo'@'%'

  6. #6
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,515
    Thanks
    17
    Thanked 814 Times in 511 Posts
    Rep Power
    10

    Default

    You need to set userName varaible with actual username. If you want to delete a user called vivek, it must be set to vivek:

    Code:
     userName="vivek"
    Also, you need to specify @localhost i.e.:
    Code:
     mysql -u username -p'Password' -e "DROP USER $userName@localhost;"
    To view grants see:
    Code:
    mysql -u root -p'password' mysql -e "SHOW GRANTS for $userName@localhost;"
    HTH
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  7. #7
    Member
    Join Date
    Jul 2009
    Posts
    75
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    6

    Default [solved]

    you are the best it work

    thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 30th May 2009, 09:31 PM
  2. shell script to zip old files and then delete
    By shankar43 in forum Shell scripting
    Replies: 2
    Last Post: 13th March 2009, 09:10 AM
  3. Shell Script to Automatically Delete a File via Cron Job
    By kakarla in forum Shell scripting
    Replies: 2
    Last Post: 29th January 2008, 08:54 AM
  4. Linux delete mail for root or any other user from a shell prompt
    By raj in forum Getting started tutorials
    Replies: 0
    Last Post: 5th May 2007, 01:36 AM
  5. Shell script to delete a file with a dialog utility
    By shankar100 in forum Shell scripting
    Replies: 4
    Last Post: 2nd March 2007, 10:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •