Make A New MySQL Admin User

This works for both MySQL and MariaDB, so if you’re sticking with Oracle or you prefer the open source alternative, this should not cause you any trouble. After you are done installing either, you should be able to get into the command line interface by running the following as root:

mysql

On either true MySQL systems or MySQL-compatible MariaDB systems, you should be accessing the new database as root. I believe it’s bad practice to continue using the root user to modify the database. From here, we want to create a new administrator. To do that, we can use the following statements, in order, at the prompt:

drop user 'www-data'@'localhost';

create user
    'www-data'@'localhost'
identified by
    'password';

grant all on *.* to 'www-data'@'localhost' with grant option;

The first statement will fail if you do not already have a user named www-data. These statements, when executed in order, removes the www-data user (if there is one) from MySQL and creates an entirely new user by the name of www-data, granting it all privileges, including the ability to grant permissions to other users.

If you prefer a one-liner, run this as root in your BASH shell:

echo "drop user 'www-data'@'localhost'; create user 'www-data'@'localhost' identified by 'password'; grant all on *.* to 'www-data'@'localhost' with grant option;" | mysql

Just don’t be an idiot and blindly run any of the statements above without fully understanding what you are doing. You’d be creating a www-user with the password “password.”