Create new admin user mysql
To create a new admin user in MySQL, you can use the following command:
CREATE USER 'new_admin'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'new_admin'@'%';
FLUSH PRIVILEGES;
Let me explain what each line does:
CREATE USER 'new_admin'@'%' IDENTIFIED BY 'password';
: This line creates a new user namednew_admin
with a password ofpassword
. The%
symbol is a wildcard that allows the user to connect from any host.GRANT ALL PRIVILEGES ON *.* TO 'new_admin'@'%';
: This line grants all privileges to the new user on all databases (*.*
). TheGRANT
statement is used to assign privileges to a user.FLUSH PRIVILEGES;
: This line reloads the privilege tables in the MySQL database, which is necessary to make the new user's privileges take effect.
Note: You should replace new_admin
and password
with the desired username and password for your new admin user.
Also, if you want to grant specific privileges to the new user, you can use the GRANT
statement with specific privileges, for example:
GRANT SELECT, INSERT, UPDATE, DELETE ON database_name.* TO 'new_admin'@'%';
This will grant the new user the ability to select, insert, update, and delete data in the database_name
database.
It's also a good practice to create a separate database for the new admin user and grant privileges on that database only:
CREATE DATABASE new_admin_db;
GRANT ALL PRIVILEGES ON new_admin_db.* TO 'new_admin'@'%';
This way, the new admin user will only have access to the new_admin_db
database and not to other databases in the MySQL server.