Minggu, 27 Maret 2011

How to Get Prompted To Enter MySQL Password in MySQL Command?

QUESTION
In entering the MySQL command to connect to a MySQL database server in Unix how do I enter the command and then get prompted to enter the password so that it's not displayed on the screen?

ANSWER
The MySQL command to connect to a MySQL server is simple. You can use '-p' flag followed by the password like the following (assuming user is root and password is MyPassWord and you want to connect to localhost):

mysql -uroot -pMyPassWord
Let's say you'd like to enter the password passively meaning you'd like to get prompted to enter the password so that while you do it the password is not shown on the screen. The following is a failed attempt:

savior@myUnixBox:~$ mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

This would work if 'root' does NOT have a password. This is not true because it does have a password. The correct command is the following:

savior@myUnixBox:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 808754
Server version: 5.0.67-0ubuntu6 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Any questions?

Install MySQL Include Files On Unix

Q: While installing Sphinx search engine I get an error saying I have to install MySQL include files. How do I do it?

My Unix version is Ubuntu 9.10. Here's what happens. When I run ./configure tool to install Sphinx I got the following error:

configure: error: invalid MySQL root directory '/var/lib/mysql'; neither bin/mysql_config, nor include/ and lib/ were found there
To give you some context into why this is needed, if you install any application that needs to communicate with your MySQL server you'll have to let that application know the MySQL protocol via MySQL libraries in the form of MySQL include files. Note this problem is NOT limited to Sphinx search engine only; whatever Unix application software that needs to talk to MySQL server also applies!

To solve this error I needed to use 'apt-get' to install libmysql++-dev. However when I run 'sudo apt-get install libmysql++-dev' it says it cannot find the library and asks me to run 'apt-get update', but when I do that I get a bunch of 404 errors:

Ign http://security.ubuntu.com intrepid-security Release.gpg
Ign http://security.ubuntu.com intrepid-security/main Translation-en_US
Ign http://security.ubuntu.com intrepid-security/restricted Translation-en_US
Ign http://archive.ubuntu.com intrepid Release.gpg
...
Ign http://archive.ubuntu.com intrepid-updates/restricted Packages
Ign http://archive.ubuntu.com intrepid-updates/universe Packages
Ign http://archive.ubuntu.com intrepid-updates/main Sources
Err http://security.ubuntu.com intrepid-security/main Packages
404 Not Found [IP: 91.189.92.167 80]
Err http://security.ubuntu.com intrepid-security/restricted Packages
404 Not Found [IP: 91.189.92.167 80]
...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/intrepid-updates/restricted/source/Sources.gz 404 Not Found [IP: 91.189.92.169 80]

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/intrepid-updates/universe/source/Sources.gz 404 Not Found [IP: 91.189.92.169 80]

E: Some index files failed to download, they have been ignored, or old ones used instead.

==== or the following error ====

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

This happens because my repositories are out of date. So I updated my sources.list (Where is sources.list? It is usually located at /etc/apt/sources.list) to (after backing it up of course) to the default of Ubuntu 9.10 which is the following:

# deb cdrom:[Ubuntu-Server 9.10 _Karmic Koala_ - Release i386 (20091027.2)]/ karmic main restricted

#deb cdrom:[Ubuntu-Server 9.10 _Karmic Koala_ - Release i386 (20091027.2)]/ karmic main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.

deb http://us.archive.ubuntu.com/ubuntu/ karmic main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://us.archive.ubuntu.com/ubuntu/ karmic multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic multiverse
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://us.archive.ubuntu.com/ubuntu/ karmic-backports main restricted universe multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu karmic partner
# deb-src http://archive.canonical.com/ubuntu karmic partner

deb http://security.ubuntu.com/ubuntu karmic-security main restricted
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted
deb http://security.ubuntu.com/ubuntu karmic-security universe
deb-src http://security.ubuntu.com/ubuntu karmic-security universe
deb http://security.ubuntu.com/ubuntu karmic-security multiverse
deb-src http://security.ubuntu.com/ubuntu karmic-security multiverse

Now I run 'apt-get update' and 'apt-get install libmysql++-dev' successfully! This time when I run configure for Sphinx it successfully recognizes the MySQL includes and is installed correctly!

Kamis, 17 Maret 2011

How Do You Escape Special Characters In Sphinx Configuration?

Q: My database password contains bang character (!) and when I specify the password in sphinx config I keep getting errors. Why?

SOLUTION
It goes without saying that it must have something to do with escaping special characters! How nasty is that? And the Sphinx user manual does not really mention how to deal with special characters. Anyway the solution is that you simply use backslash (\) to escape special characters. Suppose my host is localhost and user name is root and password is crack!t, then here's a typical 'source' block in sphinx configuration:

source someSource
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = crack\!t
sql_db = mffl
sql_port = 3306

sql_query = \
select store_id+1000,store_id as id,'store' as type,title,title as data,body from store union \
select brand_id+2000,brand_id as id,'brand' as type,title,title as data,body from brand union \
select style_id+3000,style_id as id,'keyword' as type,title,title as data,body from keyword

sql_attr_uint = id
sql_attr_uint = sort
sql_attr_string = type
sql_field_string = title
sql_field_string = data
}


Note how I escape the exclamation mark in sql_pass with a backslash (\) haha!

How Do You 301 Redirect a Naked Domain To a Subdomain such as www

QUESTION
How do you 301 redirect a naked domain to some sub domain, most commonly www, so that when someone goes to yourDomain.com they'll be 301 redirected to www.yourDomain.com?

ANSWER
For those who don't understand what 301 redirect is here's a quick answer. When your webpage has been moved to a new place you usually want to set your web server to tell whoever wanting to access your old webpage that it's been moved to a new place permanently. This behavior is realized with a 301 redirect. If the client is a search engine they'll know your web page has been moved permanently.

There are at least 2 ways to 301 redirect a naked domain to a subdomain:

1: In your IP host setting add an 'A record' with host @ and configure your web server accordingly.

2: Have your domain name registry do that for you.


Below we'll look at each method in more detail and also look at the pros and cons of each.

1. In your web host setting add an 'A record' with Host set to @ that points to your machine's IP and configure your web server accordingly.
In your web host setting add an 'A record' with Host set to @ that points to your machine's IP.

If you use GoDaddy.com here's a screen shot of that setting:

GoDaddy DNS Manager A Host Setting For Naked Domain

Once you finish the setting you may need to wait for up to 1 hour for the setting to take effect. Then configure your web server to recognize the naked domain and 301 redirect it to any subdomain you want such as www. This depends on the capabilities of your web server but it should have this feature. For example if you use Nginx and your domain is mensfashionforless.com then here's what you put in your web server's configuration file:

server {
listen 80;
server_name mensfashionforless.com;
rewrite ^/(.*) http://www.mensfashionforless.com/$1 permanent;
}


This rule simply means that the web server listens on port 80 and it responds to domain name 'mensfashionforless.com' by 301 redirecting it to 'www.mensfashionforless.com' (what 'permanent' means).

In fact, this rule exhibits a great benefit that this way offers: You have total control over how the redirect happens. In this case you'll be able to redirect http://mensfashionforless.com/some-page.html to http://www.mensfashionforless.com/some-page.html. Again you have total control.

2. Have your domain name registry do that for you.
Have your domain name registry (e.g. GoDaddy) do that for you (read http://www.printfection.com/help/article.php?articleid=41 if you use GoDaddy). Basically you'll be able to pick 'Forward Domain' option to forward your naked domain, or non-www domain, to any domain you'd like via 301 redirect. Typically you'd forward your naked domain to your www domain but you can actually forward it to any domain you want.

This depends on the abilities of the registry you registered your domain with but they usually have this functionality.

This way is very limited because you might not be able to forward your old path to your new path. For example you might want to redirect http://mensfashionforless.com/some-page.html to http://www.mensfashionforless.com/some-page.html but whether you can do this totally depends on your web host. In addition your web host, although unlikely, can alter their functionality any time they want. You are basically at their mercy.

Questions? Shoot me an email.

How To Skip Password Prompt In 'Sudo' Command In Unix

QUESTION
Whenever I execute a command with 'sudo' in Unix I always get a prompt for entering my password. How do I skip entering my password?

SOLUTION
When you are writing a script and in that script would like to execute a command that requires elevated privilege, you'd have issues because you'd need to enter the password afterwords. Suppose the command you want to execute is:

sudo rm *

And your password is 'myPassWord' without quotes, then here's what you do:

echo myPassWord | sudo -S rm *

'-S' is the option provided by 'sudo' command that means it'll read the password from the standard input instead of the terminal device. That's why you can pipe your password via 'echo' and you'll be able to skip the password prompt this way.

Enjoy!

Escape Command Line Args In Unix Shell

Q: Recently I am trying to use 'mysql' to connect to my MySQL server and I'd like to include the password in the command line. My password is "Crack!t" without quotes. However when I enter the command I get an error. What should I do?

A: Escaping special characters in the command line in any Unix shell can be confusing and frustrating. For me I am merely trying to connect to a MySQL database specifying the user name and password as the parameters but I don't realize it's that difficult! Here's the complete command for me to connect to my local MySQL server with user name set to 'owner' and database set to 'mffl':

mysql -uowner mffl -pCrack!t

Obviously it doesn't work. The problem is that the bang character (!) is a special character in shells that can be used to re execute a previously entered command. Anyway the output of executing the above command looks like:

saviorsage@frankwxn:~$ mysql -uowner mffl -pCrack!t
mysql -uowner mffl -pCracktouch a
mysql Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (x86_64) using readline 5.2
Copyright (C) 2000-2008 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
...
...


It sucks doesn't it. Look below to find the solution.

Solution
To solve it, simply use \ to escape it:

mysql -uowner mffl -pCrack\!t

It should work now. If not shoot me an email. Now whenever you need to escape special characters in a command line use a backslash (\) to do it!

Jumat, 11 Maret 2011

Install Komodo Edit 6 on Natty

Just wanted to give a quick update on how to install the latest Komodo Edit on the latest Ubuntu. Its been a while since I posted the last article about Komodo Edit and it needed a quick refresh.

  • The packages for Linux can be found here. Download the appropriate package for whether you have 32-bit or 64-bit.
  • Use either the GUI to extract the contents or
tar -xvzf Komodo-version-platform.tar.gz
  • In your terminal, or open a terminal if you haven't already, change to the new directory
cd Komodo-version-platform
  • Run the install script. I had to use sudo before the script to get it to install.
sudo ./install.sh
  • Go through and answer all of the installer prompts
  • Once the installer finishes you will need to add Komodo Edit to your PATH. Personally I like the symlink method, but it does require root/sudo access.
ln -s /bin/komodo /usr/bin/komodo
Two caveats that I have found is that you probably should not install to the default because it will only work for root or if you sudo. I went ahead and installed to /opt/komodo, but you could install wherever you like to install your non-package maintained software. Second, the installer actually tells you to make the symbolic link in /usr/local/bin but I have found that is not in the default PATH of the users (though it could be added). Other than that it is pretty straight forward. Let me know if you all find any other pain points.

Sabtu, 05 Maret 2011

Replace Unity Interface

I know I am not alone when I say that I don't like the new unity interface. I am using the Ubuntu Netbook Edition on my Asus EEEpc and my biggest complaint is that it is too slow. I like the idea of a better interface, but they have a long way to go to make it usable. Until then I will be sticking with the standard GNOME interface which is still included to use. I am going to show you how to change the default session to be the regular desktop session.
  • Open the Login Screen Settings dialog box.
  • Change the bottom dropdown box to be Ubuntu Desktop Edition as the default session (you can see I already have mine changed). You may need to press the Unlock button and supply your password to be able to change this setting.
  •  You should just be able to log out and back in and then you will get the familiar GNOME desktop.
This will not actually remove Unity from your installation so at what time you think you might want to use it again you could. I've read a few posts that take you through the steps to remove it, but I don't see it necessary since it can be easily disabled through the login screen.
       
      support by: infomediaku.com