The story
I've recently setup replication on my MySQL server. I went down the route of Master - Master replication (2 servers, each is Master and Slave to the other, as described here - http://brendanschwartz.com/post/12702901390/mysql-master-master-replication).
I have started to notice some queries are failing or displaying unexpected behaviour using PhpMyAdmin on WAMP. For example, suddenly:
-- This fails
SELECT * FROM `tableName` WHERE `columnName` = 10;
-- This succeeds
SELECT * FROM tableName WHERE columnName = 10;
-- In some queries, specific columns seem to be the issue
-- So even this might work, but not always
SELECT * FROM `tableName` WHERE columnName = 10;
-- Sometimes it's even due to specific columns
-- So this might succeed
SELECT * FROM `tableName` WHERE `anotherColumnName` = 10;
I soon realised it was probably PhpMyAdmin's fault as doing it via the MySQL shell worked. Then I realised it also worked on PhpMyAdmin on my own machine which is Linux based, and the PhpMyAdmin version is much newer.
However, I do run into issues with backticks when trying to run some queries from regular shell, for example:
# From my bash shell, this fails
mysql -s -uUser -pPassword -e "SELECT `columnName` FROM `dbName`.`tableName`;"
# This succeeds
mysql -s -uUser -pPassword -e "SELECT columnName FROM dbName.tableName;"
I do not believe in coincidences, so I figured I better check what's going on.
What I have so far
I have searched for it online and saw there might be an issue with backticks and replication because of the way it gets saved in the log (I think). But it still doesn't quite answer how replication is still working for me, but some queries are failing with backticks on. If anything, my data supports there are no issues with backticks.
I know what backticks are for - https://dba.stackexchange.com/questions/23129/benefits-of-using-backtick-in-mysql-queries
My MySQL servers are running:
- Ubuntu 14.04.01 (64 bit Server Edition)
- MySQL Ver 14.14 Distrib 5.5.41, for debian-linux-gnu (x86_64) using readline 6.3
My questions are:
- Why exactly are backticks bad for replication? Am I likely to run into issues with backticks or has my experience been due to esoteric, platform-specific issues?
- Is there a recommended way of dealing with this issue?
- My thinking is to get rid of all the backticks in the code. My column names are all in plain English alphabet and camelCase so I shouldn't need to use backticks anyway.
- I thought maybe I could switch to
sql_mode = ANSI_QUOTES
but I'm worried such a big change would require thorough testing of the entire system because I'm not sure how it would affect other aspects of the queries such as the values, etc. - I also thought the issue could be the backticks have become part of the name but it doesn't fit with the behaviour, and I checked.
- I thought maybe I could switch to
I would appreciate any input anyone has with regards to this issue.