Score:0

Errors importing JSON file to MySQL using mysqlsh Util.import_json

cn flag

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.)

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.