I'm going through the MySQL documentation tutorial. It's really great so far, but I've run into a problem. The step where the tut explains how to load initial table data from a file doesn't work.
Below are the steps I have taken which include a deep dive into documentation and trying many answers to similar questions (linked), all to no avail.
- I googled the error and found in the docs that loading local data is a security risk so it has to be enabled. I tried this answer and this answer, which was to use the following when logging into MySQL:
# neither of these worked:
mysql -u [username] -p --local-infile
mysql -u [username] -p --local-infile=1
mysql --local-infile -u [username] -p
Maybe when I log in with this option, I'm just setting it on the client side and not the server? I really don't know the difference.
Next, I dug into the documentation a little more and read about the "local_infile" variable. There is even a section in the documents titled Enabling or Disabling Local Data Loading Capability, where it talks about a system variable called
local_infile
but doesn't say a damned thing about how to enable or disable it.So I next read the documentation about server system variables and how to look at what I've got going on using:
mysqld --verbose --help
Which printed out a massive amount of text, but I found a line that said:
Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf C:\Program Files\MySQL\MySQL Server 8.0\my.ini C:\Program Files\MySQL\MySQL Server 8.0\my.cnf
I figured I could find my local_infile
variable in one of those .ini
or .cnf
files and change it to 1 or True or whatever... However, exactly none of those files exist in any of those locations.
- Using this answer, or more specifically the comments on the
answer, I found this file:
mysql.conf.sample
which has a few variables listed in it but notlocal_infile
, nor the host of others that were listed in the print out frommysqld --verbose --help
. To this file I added the lines
[mysqld]
local_infile=1
No luck there.
SET GLOBAL local_infile='ON'
and thenSHOW GLOBAL VARIABLES LIKE
local_infile` results in:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | ON |
+---------------+-------+
It was OFF
before. But guess what, I still can't load two rows into a database from a text file. Shocker.
- I found a blog post that said that config files could be located in the directory
%PROGRAMDATA%/MySQL/MySQL Server 8.0
as amy.ini
. Sure enough, that's where it was. I addedlocal-infile=1
under[mysql]
and[mysqld]
. It still didn't work, so I triedlocal-infile
andlocal-infile=ON
(I have seen all of these used in various accepted answers). None of them worked.
So, as is the norm, documentation absolutely sucks, and I'm lost. But at least I've done my due diligence of searching the docs, so the pedantics of SO are satisfied and I can ask my question:
How do I enable loading local data by default?