Add new Mysql user with root privileges

How to add a user with root privileges to the mysql, mariadb

mysql -uroot -p

Now enter the users information, username,host to allow acces from and password

CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';

NOTE: in mysql you are using the % sign as wildcard. As example by using the % in the host field you are allowing access from everywhere. You can also limit the access to a subnet like 192.168.%, that will allow access to the database from all hosts starting with 192.168. in the ip-address.

Then we will grant the users permissions, like GRANT ALL

GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'%' WITH GRANT OPTION;

To make the changes active we will flush privileges

FLUSH PRIVILEGES;

The user with root access should now been created and active.

To get a list of MySQL users:

select user,host from mysql.user;

To find the privilege(s) granted to a particular MySQL account:

show grants for 'root'@'%';

Skriv et svar