select * from table where column = something or, when unavailable, column = something else

You can provide a custom ordering, then take the first row, like this: Explanation: The inner select’s order by field(LOCALE, ‘ge’, ‘_’) gets you the rows in the order you define – in this case German first if it exists, then English (you could add more languages to the list). The “trick” here is using mysql’s “non-standard” GROUP … Read more

Drop all databases in MySQL

We have many databases in our MySQL and we want to shrink/purge ibdata1 file in MySQL. How can we drop all the databases from the MySQL except information_schema and mysqld databases?

Remove Primary Key in MySQL

Without an index, maintaining an autoincrement column becomes too expensive, that’s why MySQL requires an autoincrement column to be a leftmost part of an index. You should remove the autoincrement property before dropping the key: Note that you have a composite PRIMARY KEY which covers all three columns and id is not guaranteed to be … Read more

Node.js MySQL – Error: connect ECONNREFUSED

I use Node.js server side. I tried my code on localhost and everything works fine. I bought a server and installed Apache and node.js on it and test my web application there. I correctly changed the MySQL connection configurations from localhost to the server configurations. I test my web application with this configuration: I start … Read more

How to unblock with mysqladmin flush hosts

mysqladmin is not a SQL statement. It’s a little helper utility program you’ll find on your MySQL server… and “flush-hosts” is one of the things it can do. (“status” and “shutdown” are a couple of other things that come to mind). You type that command from a shell prompt. Alternately, from your query browser (such … Read more

SQL – IF EXISTS UPDATE ELSE INSERT INTO

What I’m trying to do is INSERT subscribers in my database, but IF EXISTS it should UPDATE the row, ELSE INSERT INTO a new row. Ofcourse I connect to the database first and GET the $name, $email and $birthday from the url string. This works, but just adds the new row; Here’s what I tried; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)