To create a new database on MySQL, you will need to create the database, then setup a user for that database so that you can access it for querying at a later stage.
The code to create a database is very simple:
CREATE DATABASE database_name;
You will have to swap “database_name” for the name of your database. This will create the database but will not create any users for it, so the only way you would be able to query this database would be by logging in as the root user, which is not smart if this database is a client database sat on shared hosting as you will need to divulge the root login details to each individual client so they may insert the details into their source code whereever they use the database.
What should be done is to setup a user for the database that only has access to that database and here is how to do that:
GRANT ALL PRIVILEGES ON database_name.* to database_user@localhost IDENTIFIED BY ‘database_password’;
Similarly to the first example, you would need to swap “database_user” for your chosen username and “database_password” for your chosen password.
This line of code will grant all privileges, ie INSERT, UPDATE, SELECT, CREATE, DROP etc etc to the user specified as long as they login with the specified password.