Mysql function TO_SECONDS doesn't exist - mysql

I've been passing through this problem for one day, and it's hard to understand why MySql doesn't work easily.
I'm trying to execute the statement below, but it isn't recognized at all.
SELECT TO_SECONDS('2013-09-12 11:15:00');
I get the following error:
ERROR 1305 (42000): FUNCTION db.to_seconds does not exist
I've checked MySQL's documentation and this function is available since version 5.5. So, I updated my previous version and now I'm working with 6.0 (Server version: 6.0.4-alpha-community-log MySQL Community Server (GPL)) but still not working.
mysql> select version();
+---------------------------+
| version() |
+---------------------------+
| 6.0.4-alpha-community-log |
+---------------------------+
1 row in set (0.03 sec)
Anyone knows what is going on?

TO_SECONDS('2013-09-12 11:15:00');
Seconds are a measure of time interval not a time datum - this therefore implies some sort of reference datum - but when there's lots to choose from, which do you want? One solution is to define your own datum:
SELECT TIME_DIFF('2013-09-12 11:15:00', '01-01-2000 00:00:00')
Or use the Unix epoch:
SELECT UNIX_TIMESTAMP('2013-09-12 11:15:00')

I was using MySQL version 6.0 that was installed by AppServ (Apache, MySQL, PHP, phpmyadmin) tool and this version of MySQL hasn't support for TO_SECONDS function. After installing MySQL 5.5 it's working perfectly.
mysql> select to_seconds('2013-09-02 13:33:59');
+-----------------------------------+
| to_seconds('2013-09-02 13:33:59') |
+-----------------------------------+
| 63545348039 |
+-----------------------------------+
1 row in set (0.00 sec)

Related

from_base64() not decoding back to original text

The from_base64() does not decode correctly. Please see the problem demo below.
mysql> select to_base64('sometext');
+-----------------------+
| to_base64('sometext') |
+-----------------------+
| c29tZXRleHQ= |
+-----------------------+
1 row in set (0.27 sec)
mysql> select from_base64('c29tZXRleHQ=');
+----------------------------------------------------------+
| from_base64('c29tZXRleHQ=') |
+----------------------------------------------------------+
| 0x736F6D6574657874 |
+----------------------------------------------------------+
1 row in set (0.00 sec)
This was working till i moved to latest ubuntu 19.10.
Server version: 8.0.19 MySQL Community Server - GPL
mysql --version
mysql Ver 8.0.19-0ubuntu0.19.10.3 for Linux on x86_64 ((Ubuntu))
This is because of the following.
--binary-as-hex
When this option is given, mysql displays binary data using hexadecimal notation (0xvalue). This occurs whether the overall output dislay format is tabular, vertical, HTML, or XML.
As of MySQL 8.0.19, when mysql operates in interactive mode, this option is enabled by default. In addition, output from the status (or \s) command includes this line when the option is enabled implicitly or explicitly:
To disable hexadecimal notation, use --skip-binary-as-hex
MySQL client options

Inconsistency in Tables - Galera Cluster

MariaDB cluster Version : mysql Ver 15.1 Distrib 10.0.24-MariaDB,
I have a two node + arbitrator cluster which is live and replicating data across nodes.
Unfortunately we found some inconsistency in some of the tables in Databases.
For instance:
Node1:
MariaDB [(none)]> select count(*) from example_db.reports;
+----------+
| count(*) |
+----------+
| 299 |
+----------+
1 row in set (0.00 sec)
Node2:
MariaDB [(none)]> select count(*) from example_db.reports;
+----------+
| count(*) |
+----------+
| 285 |
+----------+
1 row in set (0.00 sec)
Note: Not find any noticeable errors in mysql error log
What could be the reasons for these kind of inconsistency ?
Is that a bug or a known issues ?
Thank you.
I don't think there are any bugs in this very critical area.
In Galera clusters, you must check for errors after all statements, including COMMIT. (This is different than in ordinary replication.)
All tables are InnoDB, correct?

How to check version is greater than some base value?

When calling MySQL SELECT ##VERSION; or SELECT VERSION();, I get for instance '5.7.11-log'. Is there a "well-known" way to check if the version is greater (or smaller) than some major.minor.patch version? If not a well-known way, is there a way without using a temporary table or a user-defined function (there probably is, but for a reason or another currently eludes me)? I would use this to check if there's support for JSON type type that was introduced in version 5.7.8.
Upon researching this more, it appears this is a bit tougher nut for my skills to crack. For instance, I could write something like
SELECT
SUBSTRING_INDEX(##VERSION, '.', 1) AS major,
SUBSTRING_INDEX(SUBSTRING_INDEX(##VERSION,'.', 2), '.', -1) AS minor,
SUBSTRING_INDEX(SUBSTRING_INDEX(##VERSION,'.', -2), '.', -1) AS patch;
but that isn't entirely satisfactory (e.g. see -log) and it doesn't directly check the existence of the feature.
I cross-posted this to DBA overflow How to check if feature (JSON) exists, and/or version.
Use if condition with version
mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.7.14 |
+-----------+
1 row in set (0.00 sec)
mysql> select if(VERSION() > '5.7.14' ,1,0);
+-------------------------------+
| if(VERSION() > '5.7.14' ,1,0) |
+-------------------------------+
| 0 |
+-------------------------------+
1 row in set (0.00 sec)
mysql> select if(VERSION() > '5.7.13' ,1,0);
+-------------------------------+
| if(VERSION() > '5.7.13' ,1,0) |
+-------------------------------+
| 1 |
+-------------------------------+
1 row in set (0.00 sec)
I'll cross reference the answer by Rick here. Specifically, there is special comments syntax in MySQL in which MySQL interprets a block of code either as effective MySQL SQL or as just a plain comments section. Here's a link to the documentation: http://dev.mysql.com/doc/refman/5.7/en/comments.html and a few notable examples:
SELECT /*!JSON_TYPE*/('["a", "b", 1]');
and
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;.

MySQL extratvalue range, output and parsing issues

I'm learning MySQL. My query is follows:
mysql>select extractvalue(1,1111111111111111111); // 19 1's.
output:
`+-------------------------------------+
| extractvalue(1,1111111111111111111) |
+-------------------------------------+
| 1111111111111111111 |
+-------------------------------------+
1 row in set (0.00 sec)`
But for 20 1's
mysql>select extract(1,11111111111111111111);
+--------------------------------------+
| extractvalue(1,11111111111111111111) |
+--------------------------------------+
| -7335632962598440505 |
+--------------------------------------+
1 row in set (0.00 sec)
And the following show me different errors:
mysql> select extractvalue(rand(),5.5.28));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '.28))
' at line 1
mysql> select extractvalue(rand(),version());
ERROR 1105 (HY000): XPATH syntax error: '.28'
Can someone explain me?
I tried out these, it seems to work.
SELECT #rand := RAND();
select extractvalue(1,#rand);
However, extract doesn't seem to work and gives the error. Either way I have not managed to use extract or extractvalue to wrap rand(). Reason could be that extractvalue only returns CDATA. Your intention of application doesn't seem to be supported by this function. It's used on XPATH
for e.g.
Select allhttp://www.blablabla.com/error.php?id=null
and extractvalue(rand(),concat(0x3a,(
select concat(0x3a,username,0x3a,password) from users)))
Found this to be interesting: reference

MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=10'

I am posting this to save another dev hours of wasted time. Mysql release candidate 5.6.7-rc is junk. As as dev I usually follow as closely as possible with latest version. This caused me hours of debugging gerrit and mysql. The answer is to use a stable version. I hope this helps someone else.
Not sure on the SO protocol for doing something like this - so just posting as a question.
mysql> select VERSION();
+--------------+
| VERSION() |
+--------------+
| 5.6.7-rc-log |
+--------------+
1 row in set (0.00 sec)
mysql> SET OPTION SQL_SELECT_LIMIT=10;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=10' at line 1
mysql> select VERSION();
+------------+
| VERSION() |
+------------+
| 5.5.28-log |
+------------+
1 row in set (0.00 sec)
mysql> SET OPTION SQL_SELECT_LIMIT=10;
Query OK, 0 rows affected (0.00 sec)
Older versions of MySQL employed SET OPTION, but this syntax is
deprecated in favor of SET without OPTION.
SET OPTION syntax is deprecated, and was removed in version 5.6.
You should just use SET SQL_SELECT_LIMIT=10; instead.
Look at the here.
Incompatible Change: The obsolete OPTION modifier for the SET
statement has been removed.