nginx and WordPress

You can check that your database was created by entering MySQL as root (once again, with -p and after entering the root password):


$ mysql -u root -p

Then, issue the command SHOW DATABASES at the mysql> prompt. On my completely new system, I got the following response:


mysql> SHOW DATABASES;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
4 rows in set (0.01 sec)

Notice that there are three databases in the system in addition to the "wordpress" database I created earlier. These are used internally by MySQL. Indeed, you'll now connect from the UNIX shell to the "mysql" database, which is used to run your database:


$ mysql mysql -u root -p

If you prefer, you also can switch to the "mysql" database from within the MySQL client:


mysql> \u mysql

Either way, you should now be connected to the "mysql" database as root. Next, you'll create a "wordpress" user and then allow that user to connect to your MySQL "wordpress" database.

I should note that when I work with consulting clients, it's not unusual for them to use the "root" user for all of their database connections. After all, it's more convenient, right? However, this is almost always a bad idea; you really want to have and use a separate user name for security reasons.

Once connected, you'll create a user, assign it a password and indicate that this new user has full privileges on the "wordpress" database:


mysql> CREATE USER wordpress@localhost;
mysql> SET PASSWORD FOR wordpress@localhost = PASSWORD('my-wp-pw');
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO  wordpress@localhost;
mysql> FLUSH PRIVILEGES;

Note that SQL commands are case-insensitive, so you don't need to use CAPITAL LETTERS when entering them. However, I've done so for years, following the advice of Joe Celko's SQL For Smarties books, and I've found that it helps to distinguish between other parts of my programs.

Also note that in the above scenario, you've created a "wordpress" database and a "wordpress" user. Actually, your user isn't named "wordpress" so much as "wordpress@localhost"; when connecting to MySQL, the hostname is taken into account.

Finally, the FLUSH PRIVILEGES command is necessary to tell MySQL that it should take the new privileges into account even without doing a restart of the database server.

Once this is in place, you'll want to test it to make sure you can connect to the "wordpress" database as the "wordpress" user. On the UNIX shell, type:


$ mysql wordpress -u wordpress -p

When prompted for the password, enter the password you used (which is hopefully not "my-wp-pw" from above). You should see the "welcome" message and a mysql> prompt. If that doesn't work, then double-check the user name and password that you created, and make sure you flushed the privileges.

______________________