I am having errors in attempting to import a file into MySQL (8.0.32-0ubuntu0.22.04.2) using:
mysqlsh mysqluser@localhost/jsondb --import /path/to/file.json
If the file is in, say, my home directory, regardless of what I do,
mysqlsh mysqluser@localhost/jsondb --import /home/myuser/file.json
I get:
Importing from file "/home/myuser/file.json" to collection `jsondb`.`file` in MySQL Server at localhost:33060
Processed 0 bytes in 0 documents in 0.0014 sec (0.00 documents/s)
Total successfully imported documents 0 (0.00 documents/s)
ERROR: Util.importJson: /home/myuser/file.json: Permission denied (error code 13)
Also in /var/log/syslog
:
Apr 8 09:10:43 hostname kernel: [ 8158.145542] audit: type=1400 audit(1680952123.439:53): apparmor="DENIED" operation="open" profile="snap.mysql-shell.mysqlsh" name="/home/myuser/file.json" pid=3333 comm="mysqlsh" requested_mask="r" denied_mask="r" fsuid=1001 ouid=118
I have attempted disabling apparmor about any way I could, short of uninstalling it altogether: disabling it; installing apparmor-utils
and running aa-disable mysqld
(and restarting mysql). I changed permission to 777
, gave ownership to mysql:mysql
; the same result every time.
Now, if I copy the json file to /tmp
or /var/mysql
(even assigning ownership to mysql:mysql
and giving 777
permissions) the error is:
ERROR: Util.importJson: Path "/tmp/file.json" does not exist.
Also, if I put the file in /home/mysql/file.json
with chown -R mysql:mysql /home/mysql
, I also get the "Access denied" error.
However, if I move it to /mysql/file.json
(with mysql:mysql
having ownership of /mysql
, I get "Path does not exist."
It seems that if I put the file in a path that is not natively accessible to the mysql
user all the way from /
, Apparmor denies access to the file. However, if it seems that MySQL will have rights to the file, it returns "Path does not exist."
I should also note that I had to use actual MySQL and not Mariadb, as I could see no way of installing mysqlx
in Mariadb. (Both were from the Ubuntu repository.)