0

I am trying to create a table book which tags column datatype is json But here is getting error message -

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB' at line 4

Query:

CREATE TABLE `book` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(200) NOT NULL,
  `tags` json DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

How to support json datatype in MySQL?

wchiquito
  • 16,177
  • 2
  • 34
  • 45
Chinmay235
  • 3,236
  • 8
  • 62
  • 93

1 Answers1

0

Upgrade to at least MySQL 5.7.8. See JSON datatype docs:

As of MySQL 5.7.8, MySQL supports a native JSON data type defined by RFC 7159 that enables efficient access to data in JSON (JavaScript Object Notation) documents.

saaj
  • 23,253
  • 3
  • 104
  • 105
  • So you have MariaDB 10.1 and you need 10.2 - https://mariadb.com/resources/blog/json-mariadb-102 – Mark Nov 22 '17 at 10:47
  • @Mark Yes it is `mysql Ver 15.1 Distrib 10.1.28-MariaDB, for Win32 (AMD64)` How to upgrade it? – Chinmay235 Nov 22 '17 at 10:50
  • @Chinmay235 You won't have it with "xampp" because even latest release has only MariaDB 10.1.21. [The blog post](https://mariadb.com/resources/blog/json-mariadb-102) on MariaDB 10.2 says *...even though a JSON datatype isn't implemented yet*. Google how to install MySQL, it shouldn't be a big deal. – saaj Nov 22 '17 at 10:51
  • i prefer mongodb for json data, it saves your times, or you can use sequelize ORM for mysql(which helps you to avoid writing raw queries) – Mohamed Sameer Nov 22 '17 at 10:52