Portland Web Design Professionals

MySQL 5.5.11 Setting Security

Blog,Website Development 1 Comment

If you’re coming from the installation tutorial, congratulations! I’m glad that you made it this far. It took me three days to figure that out myself.

Restarting MySQL Without Permissions Table

The first step to setting your administrative password is to shutdown MySQL, because we have to restart it without the ACL loading.

$ /etc/init.d/mysql stop

Alright, so now restart MySQL using this command in order to ignore the permissions system.

$ /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

Setting your Passwords

There’s a couple ways to reset your password, this is just one way.

$ mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

You can’t just use restart at this point, you’ll need to stop mysql first and then start it.

$ /etc/init.d/mysql stop
$ /etc/init.d/mysql start

Now you can load mysql and test it out.

$ mysql -u root -p

MySQL 5.5.11 Possible Errors During Installation

Blog,Website Development No Comments

I’ve compiled this list of errors that I’ve been running into during the installation of MySQL. Here’s the process that I’ve been figuring out, the results have become a tutorial, Installation MySQL 5.5.11.

Can’t start server: Bind on TCP/IP port: Address already in use

Do you already have another mysqld server running on port: 3306 ?.. Aborting. Is an error that I received during this installation process.

To fix this error I use the Killing Processes procedure to stop the instance of mysqld that was arleady running.

mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

It seems that the pid file isn’t being created. This file only contains the process number for the OS. Otherwise its an empty file. Possible causes of this happening are 80% of the time lead back to your my.cnf variables. The other 20% are caused by file or folder permissions.

Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

Normally this is caused by a bad variable in your /etc/my.cnf file. Once you fix your my.cnf file then restart mysql using this command.

$ /usr/local/mysql/bin/mysqld_safe --user=mysql

MySQL 5.5.11 Installation Debugging – Step Three

Blog,Website Development No Comments

There’s no shortage of problems when trying to do something simple, especially when we’re pirating into new territory. This is a compilation of commands that you can use in order to debug your MySQL problems. I hope that these help.

FYI: I found this nice reference manual while stumbling around google. MySQL Reference for OS X

Stopping Processes

If you had entered a command and you want to stop the process then try this.

Hold Ctrl + C

Killing Processes

First things first you need to locate the process number. This is a lot like using Ctrl + Alt + Delete and loading the windows process manager to end a process.

ps aux | grep mysql

Once you’ve located the five digit number thats assigned to the process that you want to stop, you’ll run the kill command and pass the number as the parameter.

$ kill 12345

Error Logs

First things first, you’ve got to check your error logs.

$ less /var/log/mysql/error.log

Use your arrow keys to navigate the file. To exit this view use the following:

Hold Ctrl + Z

Viewing a Commands Thought Process

This command will print out everything as the command walks through the code. You’ll see all of the system errors as they happen… if any.

$ sh -x /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --defaults-file=/etc/my.cnf --user=root

Viewing the Results of the Installation

The installation command will setup the mysql database that runs all of the sub databases that you will later setup. To see a directory listing of the files that were installed, if any, within your directories, then run this command. Be sure to change out the directory path with the directory that you want to view.

$ ls -l /var/lib/mysql
$ ls -l /var/lib/mysql/mysql

MySQL 5.5.11 Installation Tutorial – Step Two

Blog,Website Development No Comments

If you haven’t backed up your system yet, then head back to step one: Backing up MySQL

Alright, this second step assumes that you have a server thats not running MySQL. I’m using Ubuntu 9.04 (Jaunty Jackalope) and installing MySQL 5.5.11. If you run into any problems, go ahead and post the problem in the comments along with any solution that you find. I apologize but I probably willn’t be able to provide support to help you with all of the problems that you guys will most likely run into.

Download the binary

For the purposes of this tutorial I’ll be using the latest MySQL version, 5.5.11. I was able to finally locate the proper installation package from this helpful directory: SoftAgency.net. FYI, this download from server to server took me about thirty minutes.

$ cd /tmp/
$ chmod -R 777 .
$ wget http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.11-linux2.6-i686.tar.gz

Install the asynchronous I/O library

This is so that we can take advantage of the asynchronous I/O capability in the new InnoDB plugin that ships with MySQL 5.5

$ apt-get install libaio-dev

Untar the archive

$ tar xzvf mysql-5.5.11-linux2.6-i686.tar.gz

Add the path to MySQL bin directory to the PATH variable

Your environment file may look different than this. The point here is to add the /usr/local/mysql/bin to the paths.

$ vim /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/mysql/bin"
$ source /etc/environment

Making sure that we have the proper users and groups

You can skip this step if you had MySQL previously installed on your system.

$ groupadd mysql
$ useradd -r -g mysql mysql

Create the socket directory

Here again, setting the correct permissions on the socket directory is very important, otherwise MySQL would not run.

$ mkdir /var/run/mysqld/
$ chown -R mysql:mysql /var/run/mysqld/

Copy or move the untarred MySQL directory to the installation directory

It would make sense to do this prior to setting the environment paths, however, this is the point at which I find myself restarting this process over and over again until I get it right.

$ cp -R mysql-5.5.11-linux2.6-i686 /usr/local/
$ cd /usr/local/
$ ln -s mysql-5.5.11-linux2.6-i686 mysql

Consider this Checkpoint One.

Set the correct file and directory permissions on the MySQL installation directory

Setting correct permissions is very important, and setting them in the proper order is even more important. The first step is to set everything to mysql for the installation and then we’ll set them back to root for security reasons. Make certain that you’re in the /usr/local/mysql directory or you’re going to cause some major issues.

$ cd /
$ chown -R mysql:mysql /usr/local/mysql
$ chown -R mysql:mysql /var/lib/mysql
$ chown -R mysql:mysql /var/run/mysql
$ chown -R mysql:mysql /var/run/mysqld

Copy the sample MySQL configuration file to the etc directory and setup the paths

I actually had to look inside my support-files directory and see what .cnf files were available to me. Depending on what you downloaded, yours may differ from my-huge.cnf.

$ cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf

Now edit /etc/my.cnf so that it has the following values:

[client]
user = mysql
socket = /var/run/mysql/mysql.sock
port = 3306

[mysql.server]
user = mysql
basedir = /var/lib/mysql/mysql

[safe_mysqld]
err-log = /var/log/mysql/mysqld.log

[mysqld]
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
pid-file = /var/run/mysqld/mysqld.pid
basedir = /usr/local/mysql
#/path/to/datadir/mysql
datadir = /var/lib/mysql/mysql
tmpdir = /tmp
log_error = /var/log/mysql/error.log
#You need to update this to your servers IP address
bind-address = 0.0.0.0

Run the Installation Script

The official installation guide suggests that you run this command prior to moving or adjusting the my.cnf file, however, I’ve found it more beneficial to use the my.cnf file as the defaults when running this installation script.

$ cd /usr/local/mysql
$ /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql

Copy the MySQL server startup script to the startup directory

The MySQL startup script has to be placed in the directory where all the startup scripts reside, so that MySQL starts on system startup. Make sure that you make the startup script executable, and update the rc.d database to notify the system about the presence of a new startup script.

$ cd /usr/local/mysql/support-files/
$ cp mysql.server /etc/init.d/mysql
$ chmod +x /etc/init.d/mysql
$ update-rc.d mysql defaults

I ran into a lot of problems with mysqld not being installed as well, so I peered inside my support-files directory again and located the mysqld server file and repeated these steps.

$ cp mysqld_multi.server /etc/init.d/mysqld
$ chmod +x /etc/init.d/mysqld
$ update-rc.d mysqld defaults

Starting MySQL in safe mode

When starting the MySQL server for the first time after the new installation, it has to be started without the grants table, for two reasons. Firstly, because we want to retain the users and privileges data from the previous install of MySQL and secondly, because the schema of the grants table in MySQL 5.5 has changed.

So what we will do is start MySQL without the grants table, import the users and privileges data we backed up earlier in this guide and run the mysql_upgrade script that modifies the schema of the grants table to be in sync with that in MySQL 5.5. After that we will be able to run MySQL normally and have all the users and privileges same as in the previous version we had.

$ /usr/local/mysql/bin/mysqld_safe --user=mysql

Let’s check to see if we can call mysql

If you’re system throws any errors, well then, something went wrong and you need to start over from the last checkpoint. Otherwise, PHEW *wipe your brow* and proceed with the restoration of your backups.

$ mysql

If starting MySQL failed, have no fear, a lot of people are having the same problems that you’re having. Your next step is to open step three along side step two and work yourself through this process, Step Three – Debugging.

Consider this Checkpoint Two.

Loading your backups

Navigate to your backup directory and run the sql dump file. I actually ran into a problem at this step and had to finish configuring the security/passwords before I could finish restoring my old databases. Have a look here Setting MySQL Passwords and Security.

$ cd /root/mysql-5.1-dump
$ mysql < mysql.sql

Run the upgrade script so that everything gets upgraded to the version 5.5

$ mysql_upgrade

Stop the server and start it normally

$ /etc/init.d/mysql stop
$ /etc/init.d/mysql start

There you go, you have a MySQL 5.5 server up and running in no time! Do share your problems and your fixes with the rest of us. For those of you that are moving on to the next phase, I suggest that you head to the next step of setting up your passwords and securing your MySQL server installation MySQL Security.

MySQL 5.5.11 Installation Tutorial – Step One

Website Development No Comments

An application that I’m looking to install has set MySQL 5.5+ as an installation requirement. This tutorial has spawned out of three days of attempting to get MySQL upgraded from 5.1 to 5.5. Since this was the best tutorial that I was able to find (http://www.ovaistariq.net/490/a-step-by-step-guide-to-upgrading-to-mysql-5-5/), I’ll give Ovais Tariq a plug here. Although the Ovais Tariq tutorial was very informative and helpful, it didn’t actually work for me. Although I do feel that it got close, so I’m rewriting it here with my experiences to helpfully assist some others.

I’ll be breaking this tutorial down into two parts: the first part is backing up and removing mysql from your current server; the second part of this tutorial is the installation of MySQL 5.5.11, found here.

Backup the MySQL configuration

$ mkdir /root/mysql-5.1-conf
$ cp -R /etc/mysql/ /root/mysql-5.1-conf

Backup the data directory

We will be backing up the data in the form of SQL dump as well as by copying the data files over to a safe place, just to be 100% sure about the data not getting lost.

$ mkdir /root/mysql-5.1-data
$ cp -R /var/lib/mysql/ /root/mysql-5.1-data

Backup the data as SQL dump

Backup the mysql database separately and not with all the other databases, because we are going to need it before we restore all the databases.

$ mkdir /root/mysql-5.1-dump
$ mysqldump -u user_name -p --databases mysql > /root/mysql-5.1-dump/mysql.sql
$ mysqldump -u user_name -p --databases db_name > /root/mysql-5.1-dump/db_name.sql

Secondary Backups

Backups are essential, I had a copy of phpmyadmin installed, so I took advantage of this and exported all of the databases into a gzip file and saved it to my desktop.

Secondary MySQL Server for Production sites

For my situation I’m working on a clients server that contains both, the development site as well as the production site. I used our 5Twenty Studios server and setup a database for the production website. I then redirected the production site to this new database while I upgrade the server.

As a test I shut down mysql on the server and confirmed that the dev site was offline and that the production site was alive and well.

$ /etc/init.d/mysql stop

Remove the older version of MySQL

Now is the time to remove the older version of MySQL, in this case I assume the older version to be MySQL 5.1

$ apt-get remove mysql-server-5.1
$ apt-get autoremove
$ apt-get remove mysql-client
$ apt-get autoremove

Remove the MySQL files from the older version

$ rm -R /var/lib/mysql
$ rm -R /etc/mysql
$ rm -R /usr/lib/mysql

I had to run through this installation process multiple times over the course of three days, so I used this next command to search for all of the mysql instances on my server and removed them. I wanted to make sure that I was working with a blank slate.

$ find / | grep mysql

Alright, now that you’re making sure that nothing is lost in this process, lets head to step two: Installing MySQL 5.5.11

WordPress Pagination

Hardpressed No Comments

WOW! I’ve been having a pain in the ass time getting pagination to work on WordPress. First off, I don’t want to use wp-pagenavi or some other plugin. I hate plugins, I would rather have my plugin running on one clean install and nothing else.

LET’S GET STARTED. This is like Pagination made super simple, seriously. I’ve taken out all the work.

Step One:
Ok, step one. Paste this code into your functions.php file. It sets up the $pagination variable for us.
(more…)

WordPress Sessions and Captcha

Hardpressed No Comments

Tonights project: Installing captcha onto a wordpress contact form.

Step One:
So the first thing that I’m going to do is locate a captcha script that I can use as my base. I found this quick little script, looks simple enough: http://www.encaps.net/software/php-captcha/

Note: Make sure that you copy the captcha.jpg image to your website and then set the correct path.

Now let’s go ahead and create the image file. I’m going to call mine captcha-image.php. First things first, get the image loading when you call your script directly. Once you’re ready, proceed to step two.
(more…)

How to get started with reviews and giveaways

Internet,Internet Marketing,Social Media Marketing No Comments

So, you want to start reviewing and hosting giveaways, huh? You are not alone!

Almost everywhere you go in the blogosphere you will encounter reviews and giveaways. But, how exactly could you start doing so too?

Lets start by (assuming you already have a blog) opening a Twitter account. If you already do, kudos! If you don’t, I’ll give you 5 minutes to go create your own account. Ready, set, GO!

Alright! Welcome back!

Twitter is the main social-networking site. It helps you get in touch with your readers and other bloggers. It gives you and your blog exposure, and maybe one day a company will start following you and they might contact you for a review and/or giveaway! I have gotten the opportunity to review new products thanks to Twitter!

Join as many PR websites as you can find. Be patience, at the beginning you might not get any opportunities, but they will start rolling in after a while.

Becoming part of communities in your niche is also a great way to attract traffic to your site. But don’t just join and expect to be seen, be active! Let people know you are out there!

So, what if a company contacts you?

Make sure you let the company know all your terms and standards. Not because they contacted you you must say yes. Set high standards. And make sure to let them know, in case of a giveaway, that they are responsible of sending the winner their prize.

Once you agreed on the terms and are waiting for your product to review, do some research on the company, get familiar with them. Also, keep in contact with the company’s representative. Let them know when you get the package and let them be the first to know that the review/giveaway is up.

You are hosting your first review/giveaway. Now what?

You must decide how people are going to enter your give away. It really depends on what you want to do. Usually there are mandatory entries and extra entries. And don’t forget to ask for their email address. You really don’t want to go through the hassle of trying to find them! Thankfully WordPress won’t let you comment unless you add your name and address!

As a mandatory entry they can follow you through Google Friend Connect or Twitter (which in my opinion is more important than GFC). You could also ask for them to visit the company’s website and choose a product they like. You name it.

Getting people to enter your giveaways

Once your post is up on your blog, spread the word! Look around the blogosphere for ‘Giveaway Linkys’. They are lists of giveaways that will let other know about what you have to offer in your blog. I have a few favorite sites where they have a lot of linky lists:

You should also use twitter. Make sure to use hash tags like #win, #giveaway, #contest, etc. That way people out of your network could find your giveaway.

If you really cannot wait!

Don’t be afraid to ask! Do your research and choose which companies you would love to work with! This is how I’ve got so many opportunities! There are a lot of companies out there that are interested on finding bloggers like you

When sending a pitch you want to keep the email simple and professional. Explain why you are contacting them and why you are interested in their products. You are basically selling your services. Tell them that you are looking forward to hearing from them. Worst case scenario they’ll say no or never even email you back!

Trust me, you won’t regret contacting them first.

Good luck and have fun!

Removing P Tags in WordPress

Internet,Website Development 5 Comments

By default WordPress will automatically inserts p tags through your content. This can seriously screw up the a layout/design and cause validation issues. There are a couple of ways to do this, depending on your technical expertise and where you would like to preventing this from taking place.

Here are the three options:

  1. Through out entire site
  2. On specific Template pages
  3. With specific page items


Through out your entire site:

Here is a quick and easy fix to stop wordpress from placing p tags anywhere within your site. You will need to open your /wp-includes/default-filters.php file and comment out the following line:
addfilter('the_content', 'wpautop');

To comment out a line in a PHP file, insert two forward slashes //  in front of the line. When your done, this is how it should look:
//addfilter('the_content', 'wpautop');

On specific template pages:

This method with allow you to stop WordPress from using theses tags on specific template pages. (i.e. page.php, home.php, index.php, or any custom template page) You will need to open the page in an editor such as the built in WordPress editor or Dreamweaver.

Locate:
<?php the_content(); ?>

and place this directly above:
<?php remove_filter (’the_content’, ‘wpautop’); ?>

it should look like this:
<?php remove_filter (‘the_content’, ‘wpautop’); ?>
<?php the_content(); ?>

With specific page items (pics, field labels, content):
This one is also fairly easy. While creating a page or post within WordPress you have the ability to type in either the “Visual” or “HTML” tab. Feel free to create the post in visual, but when you are done you will need to switch over to HTML. Locate the item you would like to remove the <p> tag on, and place <div> tags around it instead. You will need to make sure that you place div tags around each item for this to work. Below is an example:

<div>Example Item</div>

Hope this helps.  If you have a question, email it over to use via our contact form, we would be happy to help.

5 Methods of tracking ROI from Social Media Marketing

Social Media Marketing No Comments

Since Social Media Marketing came about, there has been a lot of discussion of how to track ROI. Many companies have chosen not to participate in this very dynamic marketing channel due to what some see as an inability to track this very allusive beast. Most “social media experts” will tell you that you should simply be happy associating a unjustifiable dollar amount to each fan, follower, or subscriber you enlist. This is a method, and by far the simplest one, but not the most accurate. Over the coming weeks we will take a look at 5 ways to track Social Media Marketing ROI. We will start with the simplest and end with the most technical . In between you will find great ways to find out what your investment in Social Media truly returns you

Here is a preview of the different methods we will be taking a look at:

  • Fans, Followers, & Subscribers
  • Website Analytics
  • Calls to Action
  • Direct Sales
  • Baselining company income and growth.