« Back to overview

Assume you have access to mysql with the command line as root, i.e.
mysql -uroot -proot

# Show all users
SELECT concat(user,'@',host) FROM mysql.user;

# Set root password
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somepassword');

# Remove a user
DROP USER 'user'@'%';

# Create a database
CREATE DATABASE `somedb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */;

# Create a user and assign it some rights
CREATE USER 'someuser'@'%' IDENTIFIED BY 'password';

# Grant the user some access to the db
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'%';

# if you want to use msqldump etc
GRANT PROCESS ON *.* TO 'someuser'@'%';