To create a new user and grant them privileges in MariaDB, you can follow the following steps. The following command should be entered into the MariaDB prompt.
1. Log into MariaDB as the root user. \`\`\` sudo mysql -u root -p \`\`\`
1. Create a new user. Replace ‘newuser’ with the new user’s name, and ‘password’ with the user’s password. \`\`\` CREATE USER ‘newuser’@‘localhost’ IDENTIFIED BY ‘password’; \`\`\`
1. Grant permissions to this user. The example below grants all permissions for the ‘database_name’ database. Replace ‘newuser’ and ‘database_name’ with your new user’s name and your database name respectively. \`\`\` GRANT ALL PRIVILEGES ON database\_name.\* TO ‘newuser’@‘localhost’; \`\`\`
1. If you want to grant specific privileges, use the following syntax: \`\`\` GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON database\_name.\* TO ‘newuser’@‘localhost’; \`\`\`
1. Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges. \`\`\` FLUSH PRIVILEGES; \`\`\`
1. Exit from MariaDB. \`\`\` exit; \`\`\`
Replace ‘localhost’ with ‘%’ to allow a user to connect from any host, not just the localhost. And don’t forget that your password must be secure to keep your database safe.
Always use a secure, unguessable password.