How do I find the MySQL my.cnf location

There is no internal MySQL command to trace this, it’s a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading. /etc/my.cnf /etc/mysql/my.cnf $MYSQL_HOME/my.cnf [datadir]/my.cnf ~/.my.cnf Those are the default locations MySQL looks at. If it finds more than one, it will load … Read more

Convert from MySQL datetime to another format with PHP

If you’re looking for a way to normalize a date into MySQL format, use the following The line $phpdate = strtotime( $mysqldate ) accepts a string and performs a series of heuristics to turn that string into a unix timestamp. The line $mysqldate = date( ‘Y-m-d H:i:s’, $phpdate ) uses that timestamp and PHP’s date … Read more

Trying to perform MINUS operation in MySQL

MySql does not recognise MINUS and INTERSECT, these are Oracle based operations. In MySql a user can use NOT IN as MINUS (other solutions are also there, but I liked it lot). Example:

What does it mean to escape a string?

Escaping a string means to reduce ambiguity in quotes (and other characters) used in that string. For instance, when you’re defining a string, you typically surround it in either double quotes or single quotes: But what if my string had double quotes within it? Now I have ambiguity – the interpreter doesn’t know where my … Read more

Object of class DateTime could not be converted to string

Because $newDate is an object of type DateTime, not a string. The documentation is explicit: Returns new DateTime object formatted according to the specified format. If you want to convert from a string to DateTime back to string to change the format, call DateTime::format at the end to get a formatted string out of your DateTime. ShareFollowa

MySQL > Table doesn’t exist. But it does (or it should)

Just in case anyone still cares: I had the same issue after copying a database directory directly using command If you do this with a database that uses InnoDB tables, you will get this crazy ‘table does not exist’ error mentioned above. The issue is that you need the ib* files in the root of the MySQL datadir (e.g. ibdata1, ib_logfile0 and ib_logfile1). … Read more

Generating a random & unique 8 character string using MySQL

This problem consists of two very different sub-problems: the string must be seemingly random the string must be unique While randomness is quite easily achieved, the uniqueness without a retry loop is not. This brings us to concentrate on the uniqueness first. Non-random uniqueness can trivially be achieved with AUTO_INCREMENT. So using a uniqueness-preserving, pseudo-random … Read more