mysql

Duplicate Wordpress site for local development and testing environment

Posted in mysql, wordpress on August 6th, 2009 by David – 3 Comments

1. Download all files from eg http://example.com, upload to eg http://localhost/example/.
2. Export mysql database from example.com
3. Create a local mysql database with the same user, password and database name. These can be found in wp-config.php
4. Import the database into your new local account
5. Log in to the database, and do:
[sourcecode language='sql']
update wp_options set option_value=’http://localhost/example/’ where option_id=1
[/sourcecode]
You’ll now be able to log in at http://localhost/example/wp-admin, using the same username and password as http://example.com/wp-admin.
5. In Wordpress, click ‘Settings’ and change the blog address to your local address.
6. Profit!

Unix Time in MySQL and bash

Posted in bash, mysql on February 4th, 2009 by David – Be the first to comment

A quick one today. I was working on a mysql database that used unix timestamp produced by PHP’s time() function.

I needed to be able to quickly convert this time to a human-readable format. In bash,

date -d @timestamp

is a quick way to convert.

In a terminal shell eg:

# date -d @1224992980
Sun Oct 26 14:49:40 EST 2008

In a MySQL client, you could also use

select date(from_unixtime(column_name)) from table_name;

Or if you want a little more flexibility in the output, for example outputting 27/02/09, you could do:

select date_format(from_unixtime(column_name), ‘%d/%m/%y’) from table_name;

This post is one of my most popular posts. Did you find the information you were after? Please tell me in the comments!

Create a MySQL database

Posted in mysql on January 21st, 2009 by David – Be the first to comment

I generally only need to do this once for each project, which means I don’t do it often enough to remember. Log in to the MySQL server as root, then:

create database newdb;
grant all on newdb.* to 'newuser'@'localhost' identified by 'newuser';
set password for 'newuser'@'localhost' = password('newpass');

And you’re ready to go!
Replace newdb, newuser and newpass with whatever you like.