There is no array datatype in MySQL. But you may store array in JSON array form. Of course the SQL text will be more complex in this case.
A sample:
-- create JSON column which will store an array
CREATE TABLE test (id INT, value JSON);
-- insert 2-dimension array
INSERT INTO test (id, value) VALUES
(1, '[[1,2,3], [4,5,6], [7,8,9]]'),
(11, '[[11,12,13], [14,15,16], [17,18,19]]');
-- see the data
SELECT id, CAST(value AS CHAR) FROM test;
| id |
CAST(value AS CHAR) |
| 1 |
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] |
| 11 |
[[11, 12, 13], [14, 15, 16], [17, 18, 19]] |
-- retrieve the values for an element array(1,2) which are 6 and 16
-- remember that the elements enumeration starts from zero
SELECT id, value->'$[1][2]' AS `array(1,2)` FROM test;
-- update the value for this element to 10 for the row with id=1
UPDATE test
SET value = JSON_REPLACE(value, '$[1][2]', 10)
WHERE id = 1;
-- view the result
SELECT id, CAST(value AS CHAR) FROM test;
| id |
CAST(value AS CHAR) |
| 1 |
[[1, 2, 3], [4, 5, 10], [7, 8, 9]] |
| 11 |
[[11, 12, 13], [14, 15, 16], [17, 18, 19]] |
-- update the value for the whole row to [20,21,22] for the row with id=11
UPDATE test
SET value = JSON_REPLACE(value, '$[1]', JSON_ARRAY(20,21,22))
WHERE id = 11;
-- view the result
SELECT id, CAST(value AS CHAR) FROM test;
| id |
CAST(value AS CHAR) |
| 1 |
[[1, 2, 3], [4, 5, 10], [7, 8, 9]] |
| 11 |
[[11, 12, 13], [20, 21, 22], [17, 18, 19]] |
-- retrieve the whole array as a table
SELECT test.id, jsontable.num, jsontable.`1`, jsontable.`2`, jsontable.`3`
FROM test
CROSS JOIN JSON_TABLE(test.value,
'$[*]' COLUMNS (num FOR ORDINALITY,
`1` INT PATH '$[0]',
`2` INT PATH '$[1]',
`3` INT PATH '$[2]')) jsontable;
| id |
num |
1 |
2 |
3 |
| 1 |
1 |
1 |
2 |
3 |
| 1 |
2 |
4 |
5 |
10 |
| 1 |
3 |
7 |
8 |
9 |
| 11 |
1 |
11 |
12 |
13 |
| 11 |
2 |
20 |
21 |
22 |
| 11 |
3 |
17 |
18 |
19 |
fiddle
PS. JSON is binary datatype, CAST(value AS CHAR) needed for to convert it to string.