Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:38:02+00:00 2026-06-09T11:38:02+00:00

I want to delete all users from my MySQL database with specified name regardless

  • 0

I want to delete all users from my MySQL database with specified name regardless to the host parameter. Here is what I wrote:

DELIMITER ;;

## CREATING SCHEMA
DROP SCHEMA IF EXISTS rms;;
CREATE SCHEMA rms;;

USE rms;;

## DROP USER
DROP PROCEDURE IF EXISTS PREPARE_USERS;;
CREATE PROCEDURE PREPARE_USERS()
BEGIN
    DECLARE V_RECORD_NOT_FOUND INTEGER DEFAULT 0; 
    DECLARE V_USER_HOST CHAR(60);
    DECLARE C_HOSTS_CURSOR CURSOR FOR
        SELECT host FROM mysql.user WHERE user='rms';
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET V_RECORD_NOT_FOUND = 0;

    OPEN C_HOSTS_CURSOR;

    READ_LOOP: LOOP
        FETCH C_HOSTS_CURSOR INTO V_USER_HOST;
        IF V_RECORD_NOT_FOUND != 0 THEN
            LEAVE READ_LOOP;
        END IF;

        SET @V_EXEC=CONCAT(CONCAT('DROP USER \'rms\'@\'',V_USER_HOST),'\';;');
        PREPARE V_STMT FROM @V_EXEC;
        EXECUTE V_STMT;
        DEALLOCATE PREPARE V_STMT;
    END LOOP;

    CLOSE C_HOSTS_CURSOR;

    FLUSH PRIVILEGES;

    CREATE USER 'rms'@'127.0.0.1' IDENTIFIED BY 'rms123';
    GRANT ALL ON rms.* TO 'rms'@'127.0.0.1'
    WITH MAX_USER_CONNECTIONS  250;
END;;

CALL PREPARE_USERS();;

DROP PROCEDURE IF EXISTS PREPARE_USERS;;

DELIMITER ;

But it gives me errors and I don’t know why :/ When there are no users with ‘rms’ name, it won’t even run, but if there are any, MySQL claims that they can’t be dropped even though they are.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:38:04+00:00Added an answer on June 9, 2026 at 11:38 am

    OK, I have the answer:

    SET @users = NULL;
    SELECT GROUP_CONCAT('\'',user, '\'@\'', host, '\'') INTO @users FROM mysql.user WHERE user = 'rms';
    
    SET @users = CONCAT('DROP USER ', @users);
    PREPARE stmt1 FROM @users;
    EXECUTE stmt1;
    DEALLOCATE PREPARE stmt1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete all files in a directory with a given name, except
I want to delete all subdirectories and files from a directory, but not the
I want to delete all the elements from my list: foreach (Session session in
I want to delete all predicates named a from the list. The result must
For example, let's say I want to delete from the array all continuous segments
I want to find the users(userid) from a permissions table who have all of
I'm currently designing a database (MySQL) for drink recipes and want users to be
I want to delete all records in a MySQL table where the values in
I want to delete all rows in a datatable. I use something like this:
Hi I want to delete all stuff related to rails generate scaffold at once.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.