How do we implement SQL Server IF EXISTS (SELECT) in MySQL 5.6? We would like to convert the following SQL Server statement:

IF EXISTS(SELECT OptionValue
          FROM Options
          WHERE OptionCatagory = 'General' AND
                OptionName = 'HVRCustomPortNumber')
   UPDATE Option
   SET OptionValue = @custportnum 
   WHERE OptionCatagory = 'General' AND 
         OptionName ='HVRCustomPortNumber' 
ELSE
   INSERT INTO Options (OptionCatagory, OptionName, OptionValue)
   Values
   ('General', 'HVRCustomPortNumber, @custportnum);


to MySQL version 5.6 so that it runs correctly using C# MySQL Connector .NET on Ubuntu Linux 15.10.

I tried googling how to do this and could not find any "hits" that passed the MySQL GUI Query Analyzer.
Assuming Options has a unique key on (OptionCatagory, OptionName), you can use a fake UPSERT/MERGE. More details can be found on MySQL's documentation:
INSERT ... ON DUPLICATE KEY UPDATE syntax.

INSERT INTO Options
(OptionCatagory, OptionName, OptionValue)
VALUES( 'General', 'HVRCustomPortNumber', @custportnum)
ON DUPLICATE KEY UPDATE
OptionValue = @custportnum;


The last part can also be written:

ON DUPLICATE KEY UPDATE
OptionValue = VALUES( OptionValue );