mysql | Brain Goo https://www.popmartian.com/tipsntricks Carpe Crap 'em Fri, 06 Feb 2009 17:00:59 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.10 SQL: Select duplicate rows, select indistinct rows https://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/ https://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/#comments Mon, 27 Oct 2008 16:09:29 +0000 http://www.popmartian.com/tipsntricks/?p=67 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 … Continue reading →

The post SQL: Select duplicate rows, select indistinct rows first appeared on Brain Goo.

]]>
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”.

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

The post SQL: Select duplicate rows, select indistinct rows first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2008/10/27/sql-select-duplicate-rows-select-indistinct-rows/feed/ 1
Change or recover MySQL root password https://www.popmartian.com/tipsntricks/2008/09/22/change-or-recover-mysql-root-password/ https://www.popmartian.com/tipsntricks/2008/09/22/change-or-recover-mysql-root-password/#respond Mon, 22 Sep 2008 16:02:47 +0000 http://www.popmartian.com/tipsntricks/?p=41 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 … Continue reading →

The post Change or recover MySQL root password first appeared on Brain Goo.

]]>
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!

The post Change or recover MySQL root password first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2008/09/22/change-or-recover-mysql-root-password/feed/ 0