MYSQL Creating databases
Create database, users, and grants
Create a DATABASE. Note that the shortened word SCHEMA can be used as a synonym.
If the database already exists, Error 1007 is returned. To get around this error, try:
Due to the above Error possibilities, DDL statements are often used with IF EXISTS.
One can create a database with a default CHARACTER SET and collation. For example:
See your current databases:
Set the currently active database, and see some information:
The above shows the default CHARACTER SET and Collation for the database.
Create a user:
The above creates a user John123, able to connect with any hostname due to the % wildcard. The Password for the user is set to 'OpenSesame' which is hashed.
And create another:
Show that the users have been created by examining the special mysql database:
Note that at this point, the users have been created, but without any permissions to use the Baseball database.
Work with permissions for users and databases. Grant rights to user John123 to have full privileges on the Baseball database, and just SELECT rights for the other user:
Verify the above:
Note that the GRANT USAGE that you will always see means simply that the user may login. That is all that that means.