Brain Goo

Carpe Crap ‘em

Brain Goo header image 1

SQL: Select duplicate rows, select indistinct rows

October 27th, 2008 · No Comments

Using SQL, MySQL or whatever your favorite database may be, we all know using SELECT DISTINCT will return unique values in case a value appears more than once in a table.

How do you fine duplicates? What if I want to know where the duplicates are?

The trick is to use count() and compare it to an integer.

SELECT count(*), locations.* FROM locations GROUP BY number HAVING COUNT(*) > 1

That will select a count of unique instances of a value from a table called “locations”, group them by a field called “number” where the count is greater than 1. In other words, it will return all the fields where there are more than one instance of the same value in the column “number”.

→ No CommentsTags: How Tos · SQL · mysql

Change or recover MySQL root password

September 22nd, 2008 · No Comments

To Change a Known Password
If you know the current password, use one of these methods to reset it.  If you do not know, skip ahead to the next section.

Using mysqladmin if there is no password:

$ mysqladmin -u root password <new password>

Using mysqladmin if there is a password:
$ mysqladmin -u root -p <old password> <new password>

Using mysql shell if there is no password
mysql -u root
mysql> update user set password=PASSWORD("<new password>") where User='root';
mysql> flush privileges;
mysql> quit

Using mysql shell if there is a password
mysql -u root -p
Password: <old password>
mysql> update user set password=PASSWORD("<new password>") where User='root';
mysql> flush privileges;
mysql> quit

Recover/reset the password if you don’t know it
There is no way to recover the password if you don’t know it, but you can reset it to something new.
You must have root on the box for this.

  1. Kill the running server
  2. Create a text file with the following contents:
    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
  3. Run the mysql_safe binary with the --init-file option pointing to your new file like this:
    mysqld_safe --init-file=/path/to/file &
  4. Delete the init file you created.
  5. Stop and start MySQL normally.

Did you find this post useful or have questions or comments?  Please let me know!

→ No CommentsTags: How Tos · mysql

Windows 2003 Update Group Policy

August 29th, 2008 · No Comments

From Microsoft knowledgebase article http://support.microsoft.com/kb/298444

To update the group policy, run Gpupdate.exe from a cmd window.  This is refresh any changes in the Group Policy as they apply to that machine.  Run Gpupdate.exe /Force from a cmd window in order to force a full refresh of the Group Policy.

You have to check Event Log -> Application to see if it actually succeeded.

Did you find this post useful or have questions or comments?  Please let me know!

→ No CommentsTags: How Tos