Create new root user mysql

To create a new root user in MySQL, you can use the following steps:

Method 1: Using the mysql command-line tool

  1. Open a terminal or command prompt and navigate to the MySQL installation directory.

  2. Run the following command to start the MySQL client:

    mysql -u root -p

    This will prompt you to enter the current root password. If you don't know the password, you can skip this step and use the --skip-password option instead.

  3. Once you're logged in, run the following command to create a new root user:

    CREATE USER 'new_root'@'%' IDENTIFIED BY 'new_password';

    Replace new_root with the desired username and new_password with the desired password.

  4. Grant the new user the SUPER privilege, which is required for the root user:

    GRANT SUPER ON *.* TO 'new_root'@'%';
  5. Flush the privileges to apply the changes:

    FLUSH PRIVILEGES;

    Method 2: Using the mysql_secure_installation script

  6. Run the following command to start the mysql_secure_installation script:

    mysql_secure_installation

    This script will prompt you to set a new root password, remove anonymous user accounts, and disable remote root login.

  7. When prompted to set a new root password, enter the desired password.

  8. When prompted to create a new root user, enter the desired username and password.

  9. The script will automatically grant the new user the SUPER privilege and flush the privileges.

Method 3: Using the mysql command-line tool with the --skip-password option

  1. Run the following command to start the MySQL client with the --skip-password option:
    mysql --skip-password

    This will allow you to create a new root user without entering the current root password.

  2. Run the following command to create a new root user:
    CREATE USER 'new_root'@'%' IDENTIFIED BY 'new_password';

    Replace new_root with the desired username and new_password with the desired password.

  3. Grant the new user the SUPER privilege:
    GRANT SUPER ON *.* TO 'new_root'@'%';
  4. Flush the privileges:
    FLUSH PRIVILEGES;

    Note: Make sure to replace new_root and new_password with the desired values. Also, be careful when creating a new root user, as it can potentially compromise the security of your MySQL installation.