mysql: SOURCE error 2?

Assuming you mean that you are trying to use the source command in order to execute SQL statements from a text file, the error number given appears to be passed through from the POSIX layer. Therefore, using this resource, we can deduce that the error value of 2 means “no such file or directory”. In short, you got the path … Read more

How can I loop through all rows of a table? (MySQL)

Since the suggestion of a loop implies the request for a procedure type solution. Here is mine. Any query which works on any single record taken from a table can be wrapped in a procedure to make it run through each row of a table like so: First delete any existing procedure with the same … Read more

Getting “Lock wait timeout exceeded; try restarting transaction” even though I’m not using a transaction

You are using a transaction; autocommit does not disable transactions, it just makes them automatically commit at the end of the statement. What is happening is, some other thread is holding a record lock on some record (you’re updating every record in the table!) for too long, and your thread is being timed out. You … Read more

Usage of MySQL’s “IF EXISTS”

You cannot use IF control block OUTSIDE of functions. So that affects both of your queries. Turn the EXISTS clause into a subquery instead within an IF function In fact, booleans are returned as 1 or 0

SELECT * FROM multiple tables. MySQL

What you do here is called a JOIN (although you do it implicitly because you select from multiple tables). This means, if you didn’t put any conditions in your WHERE clause, you had all combinations of those tables. Only with your condition you restrict your join to those rows where the drink id matches. But there are still X … Read more

Mysql command not found in OS X 10.7

This is the problem with your $PATH: /usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin. $PATH is where the shell searches for command files. Folders to search in need to be separated with a colon. And so you want /usr/local/mysql/bin/ in your path but instead it searches in /usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin, which probably doesn’t exist. Instead you want ${PATH}:/usr/local/mysql/bin. So do export PATH=${PATH}:/usr/local/mysql/bin. If you want this to be run … Read more

mysql update multiple columns with same now()

Found a solution: I found this in MySQL Docs and after a few tests it works: the following statement sets col2 to the current (updated) col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This behavior differs from standard SQL. UPDATE t1 SET col1 = col1 + 1, … Read more

mysqladmin: connect to server at ‘localhost’ failed

Short version: If your MySQL user root needs a password to connect, it might be a good idea to have mysqladmin provide that password 😉 Longer version: Your MySQL user root seems to need a password to connect setting the mysql root password new But mysqladmin tries to connect without a password ‘Access denied for user ‘root’@’localhost’ (using password: NO)’ And mysqladmin does that because you’re not … Read more