MySQL Commands and Headaches

Creating a database in MySQL is a breeze. Once you log into MySQL as root (or a user with "all" permissions), you simply need to type in the following commands (example as if it were "nameofdatabase":

mysql> create database nameofdatabase;

Adding a user via permission seems to work most often for me. The command works as following, if the user is "user", the server is "localhost" (meaning you are using the same server for the database), and the password is "password".

mysql> GRANT ALL PRIVILEGES ON nameofdatabase.* TO username@localhost IDENTIFIED BY 'password';

Don't forget to then flush privileges to make sure your password and new permissions will work.

mysql> flush privileges;

Now, if you want that user to be another root powered user, or a superuser, then you do the following command:

mysql> GRANT ALL PRIVILEGES ON *.* TO username@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;