Thursday, October 25, 2012

#1045 - Access denied for user 'root'@'localhost' (using password: NO)

If you're using phpMyAdmin for the first time, you probably got this error
#1045 - Access denied for user 'root'@'localhost' (using password: NO)

The solution is
  1. open mysql command window and execute the following command to change the root password
    UPDATE mysql.user SET Password=PASSWORD('******') WHERE User='root';
    FLUSH PRIVILEGES;
    where ****** are your new password.
  2. open the config.inc.php file at C:\wamp\apps\phpmyadmin3.5.1 (This location may defer depending on the version and the location you installed wamp at)

    and edit the following line using a text editor
    $cfg['Servers'][$i]['password'] = '';
    to
    $cfg['Servers'][$i]['password'] = 'xxxxx';
    where xxxxx is the password of the root account of mysql.
  3.  Restart all wamp services and it should work.
Now, IT MAY NOT WORK!!
and it didn't work for me.
I uninstalled and reinstalled.
I restarted my machine.
but it still didn't work and if frustrated me.
and the solution was really simple.
I just deleted all my browser's history, and it finally WORKED!

Friday, September 28, 2012

How to remove duplicate rows in MySQL

Sometimes your table contains duplicate keys due to the fact that you forgot to add a primary key to the initial design. Something like that
CREATE TABLE employee (
ssn INT NOT NULL,
name VARCHAR(20) NOT NULL 
);
Yeah, Bad database design!!

Here are different ways to fix it
1- You realize that a primary(unique) key is missing, so you add it
ALTER IGNORE TABLE employee ADD PRIMARY KEY (ssn);  
or
ALTER IGNORE TABLE employee ADD UNIQUE KEY (ssn); 
notice the IGNORE keyword.
You could later reverse that constraint by
ALTER TABLE employee DROP index ssn;  
or 
ALTER TABLE employee DROP index ssn; 
2- Delete all but one using LIMIT keyword

DELETE FROM employee WHERE ssn=x LIMIT n; 
where x is the value of the duplicated attribute and n is the number of required deleted rows, i.e. less than the total duplicated rows by 1.
example:
if you have a duplicated ssn = 123456789 repeated 10 times and you want to delete 9 of them

DELETE FROM employee WHERE ssn=123456789 LIMIT 9; 
You can do a COUNT on that ssn before you apply the previous command.

3- Using a temporary table
CREATE TEMPORARY TABLE employee_temp AS SELECT DISTINCT * FROM employee;
DELETE * FROM employee;
INSERT INTO employee SELECT * FROM employee_temp; 

 

Saturday, September 1, 2012

How to install .bin file in linux

1. Use chmod command to make it executable. Open the Terminal and write the following command
chmod +x file.bin
2. Run the file using the following command in the Terminal
./file.bin

Wednesday, August 15, 2012

Struts 2 - The requested resource () is not available

You are here probably because you have just created your first Struts 2 application and after deploying it on a server, you got the following message:

“HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.

This problem is a result of having more or less than the required jar files added to the build path.
Here is the solution, make sure to include exactly these jar files in the build path.
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-core-2.3.4.jar
xwork-core-2.3.4.jar

It should work.

Note: The numbers at the end of the file names may be different for the Struts release you work with.