Posts Tagged ‘mysql’

WordPress Redirection

Friday, April 30th, 2010

Whenever I go to www.domain.com it is redirected to Non-www and the browser shows domain.com . There is no redirect rules set and I checked my .htacces file. I knew it is something to do with my wordpress . My WordPress is installed in the root directory and not in its own subdirectory called /blog or /wordpress .

Here is how I fixed it . Consider my domain name is domain.com and username : doma
# mysql –user=doma –password=mypass

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 399164
Server version: 5.0.88 Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| doma |
+——————–+
2 rows in set (0.00 sec)

mysql> use doma;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+———————–+
| Tables_in_doma |
+———————–+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_terms |
| wp_usermeta |
| wp_users |
+———————–+
11 rows in set (0.00 sec)

mysql> desc wp_options;
+————–+———————+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+————–+———————+——+—–+———+—————-+
| option_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| blog_id | int(11) | NO | | 0 | |
| option_name | varchar(64) | NO | UNI | | |
| option_value | longtext | NO | | NULL | |
| autoload | varchar(20) | NO | | yes | |
+————–+———————+——+—–+———+—————-+
5 rows in set (0.00 sec)

mysql> select * from wp_options where option_name=’siteurl’;
+———–+———+————-+———————+———-+
| option_id | blog_id | option_name | option_value | autoload |
+———–+———+————-+———————+———-+
| 2 | 0 | siteurl |
http://domain.com | yes |
+———–+———+————-+———————+———-+
1 row in set (0.00 sec)

There you can see the siteurl is given without www . Below I’m going to change it to www .

mysql> update wp_options set option_value=’http://www.domain.com’ where option_name=’siteurl’;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> select * from wp_options where option_name=’home’;
+———–+———+————-+———————+———-+
| option_id | blog_id | option_name | option_value | autoload |
+———–+———+————-+———————+———-+
| 38 | 0 | home |
http://domain.com | yes |
+———–+———+————-+———————+———-+
1 row in set (0.00 sec)

mysql> update wp_options set option_value=’http://www.domain.com’ where option_name=’home’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Done . Isn’t that cool ? :)

Submitted by,

Manjula Kesavan,
System Administrator,
LogicSupport.com

Backup your MySQL Databases

Wednesday, April 21st, 2010

How many times have you come across situations when corrupt or old database eventually lost you an entire list of leads and emails collected over several years? It is heart breaking indeed. There have also been instances when the monthly backup got overwritten by the latest one and there was no way to return to the old settings. It is best to have an easy, alternate backup method in place in order to prevent losing those precious data on your server.
You can automate the backup process by making a small shell script which will create a daily backup file without overwriting the older backup .

#!/bin/sh
date=`date -I`
mysqldump –all-databases | gzip > /var/backup/backup-$date.sql.gz
Change the above directory to your backup drive location.

1) Save above script to a file eg: /root/dailybackup.sh
2) Make the file executable :- chmod +x /root/dailybackup.sh
3) Add following line in cron to take backup daily at 01:00 am

0 1 * * * /root/dailybackup.sh

Since mysqldump sends its output to the console, we can pipe the output through gzip or bzip2 and send the compressed dump to the backup file. Here’s another way of doing it with bzip2

mysqldump –all-databases -p | bzip2 -c >databasebackup.sql.bz2

Enter password:
If you wish to transfer the file to your other server and decompress it , say my backup file is

backup-2010-02-14.sql.bz

You can decompress as follows :-

bzip2 -d backup-2010-02-14.sql.bz

It will be now in the form

backup-2010-02-14.sql

Restore your backup using the mysql command:

mysql -p < backup-2010-02-14.sql

Done!

How to Re-install Mysql on Freebsd

Monday, November 30th, 2009

freebsd

Say Mysql has completely crashed on your server and while restarting it is showing the below error :-

/usr/local/bin/mysqladmin: connect to server at ‘localhost’ failed error: ‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (61)’ Check that mysqld is running and that the socket: ‘/tmp/mysql.sock’ exists! mysql has failed, please contact the sysadmin (result was “mysql has failed”).

And from the mysql error logs you are getting

/libexec/ld-elf.so.1: /lib/libc.so.7: version FBSD_1.1 required by /usr/local/libexec/mysqld not found

If you have tried all other common fixes then lets now move on to mysql-reinstall.

The steps to reinstall mysql from ports on a freebsd – cpanel servers are as follows.

# cd /usr/ports/databases/

# pkg_info | grep -i mysql

It should display information on mysql packages , something like

bsdpan-DBD-mysql-4.013 DBD::mysql – MySQL driver for the Perl5 Database Interface

mysql-client-5.0.87 Multithreaded SQL database (client)

mysql-server-5.0.87 Multithreaded SQL database (server)

cd /usr/ports/databases/mysql50-server (see which version you have)

make clean

make

make deinstall

make reinstall

/usr/local/etc/rc.d/mysql-server start

/usr/local/etc/rc.d/mysql-server.sh start

Check if mysql is running

# ps wwaux | grep mysql

Make sure that you have given the symlink

# ln -s /var/db/mysql/mysql.sock /tmp

If it still shows down try to re-set the mysql password and restart mysql again .