MySQL - Add a new User

MySQL/MariaDB are popular Databases, which are often used for data scraping, because they can handle a lot of INSERTs in a short time. In this post I will show you how to add a new user and set the permissions to access a database.

In order to connect remotely you have to bind MySQL on port 3306. You can do it by modifing the file my.cnf. Then you have to create the user for both, localhost and all external hosts (using the '%' wildcard) and grant permissions.

To bind all adresses open my.cnf and edit the bind-address like this

bind-address = 0.0.0.0

To create a new user run the following sql commands (replace myuser with your username and mypass with a proper password):

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';

GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';

Link