MySQL : LOAD DATA LOCAL INFILE 활성화
Ubuntu 12 LTS에서 Mysql 5.5를 실행하고 있습니다. my.cnf에서 LOAD DATA LOCAL INFILE을 어떻게 활성화해야합니까?
구성의 여러 위치에서 local-infile을 추가하려고 시도했지만 여전히 "이 MySQL 버전에서는 사용 된 명령을 사용할 수 없습니다"라는 메시지가 나타납니다.
MySQL 5.5 매뉴얼 페이지에서 :
LOCAL은 서버와 클라이언트가 모두 서버를 허용하도록 구성된 경우에만 작동합니다. 예를 들어, mysqld가 --local-infile = 0으로 시작된 경우 LOCAL이 작동하지 않습니다. 6.1.6 절.“LOAD DATA LOCAL의 보안 문제”를 참조하십시오.
옵션을 설정해야합니다.
local-infile=1
my.cnf 파일 의 [mysql] 항목에 넣거나 --local-infile 옵션을 사용하여 mysql 클라이언트를 호출하십시오 .
mysql --local-infile -uroot -pyourpwd yourdbname
"local infile"기능 서버 측을 활성화하려면 동일한 매개 변수가 [mysqld] 섹션에 정의되어 있는지 확인해야합니다 .
보안 제한 사항입니다.
편집해야 할 my.cnf 파일은 /etc/mysql/my.cnf 파일입니다. 다만:
sudo nano /etc/mysql/my.cnf
그런 다음 다음을 추가하십시오.
[mysqld]
local-infile
[mysql]
local-infile
헤더 [mysqld] 및 [mysql] 이 이미 제공되어 있습니다. 파일에서 헤더를 찾아 각각 아래 에 local-infile을 추가하십시오 .
Ubuntu 12.04 LTS의 MySQL 5.5에서 작동합니다.
드라이버 php5-mysql을 기본 드라이버로 교체하십시오.
데비안에서
apt-get install php5-mysqlnd
mysql 터미널 명령으로 MySQL 8.0.11 에서이 문제를 해결했습니다.
SET GLOBAL local_infile = true;
평소와 같이 먼저 로그인했음을 의미합니다.
mysql -u user -p*
그 후 다음 명령으로 상태를 볼 수 있습니다.
SHOW GLOBAL VARIABLES LIKE 'local_infile';
켜져 있어야합니다. 로컬 파일을 데이터베이스에로드 할 때 발행 된 보안에 대해서는 쓰지 않을 것입니다.
우분투에서 mysql의 맛이 작동하지 않고 여전히 1148 오류가 발생하는 경우 load data infile
명령 줄을 통해 명령을 실행할 수 있습니다
터미널 창을 엽니 다
운영 mysql -u YOURUSERNAME -p --local-infile YOURDBNAME
mysqluser 비밀번호를 입력하라는 메시지가 표시됩니다
MySQLMonitor를 실행하고 명령 프롬프트가 나타납니다. mysql>
load data infile
명령을 실행하십시오 (세미콜론으로 끝나는 것을 잊지 마십시오 ;
)
이처럼 :
load data local infile '/home/tony/Desktop/2013Mini.csv' into table Reading_Table FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
아래 이미지를 참조하십시오 ...
나는 --local-infile=1
일반적인 mysql 명령에 추가 했다mysql -u root -p
따라서 총 라인은 다음과 같습니다.
mysql --local-infile = 1 -u 루트 -p
또한 다른 독자에게 Django 에서이 작업을 시도하고 서버에서 local_infile을 허용하면 (mysql 클라이언트를 통해 SHOW VARIABLES를 입력하여 확인할 수 있음) settings.py 파일에 추가 할 수 있습니다 (python MySQLdb는 ' t 기본적으로 .my.cnf 파일을 읽습니다).
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'myname',
'PASSWORD': 'mypass',
'HOST': 'myserver',
'PORT': '3306',
'OPTIONS' : {
'local_infile':1,
},
}
}
mysqli 연결을 설정하는 방법에주의해야합니다. 이 솔루션에 대한 전체 크레딧은 Jorge Albarenque, 소스로 이동합니다
그것을 고치려면 :
- local-infile = 1을 my.cnf의 [mysqld] 및 [mysql] 섹션에 추가하십시오 (위의 설명에서 설명 함).
- mysqli_real_connect 함수 ( PHP 문서 )를 사용하십시오 .
이 기능을 사용하면 LOAD DATA LOCAL INFILE에 대한 지원을 명시 적으로 활성화 할 수 있습니다. 예를 들어 (절차 스타일) :
$link = mysqli_init();
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($link, $host, $username, $password, $database);
또는 객체 지향
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_LOCAL_INFILE, true);
$mysqli->real_connect($host, $username, $password, $database);
Another way is to use the mysqlimport
client program.
You invoke it as follows:
mysqlimport -uTheUsername -pThePassword --local yourDatabaseName tableName.txt
This generates a LOAD DATA
statement which loads tableName.txt
into the tableName
table.
Keep in mind the following:
mysqlimport
determines the table name from the file you provide; using all text from the start of the file name up to the first period as the table name. So, if you wish to load several files to the same table you could distinguish them like tableName.1.txt
, tableName.2.txt
,..., etc, for example.
if your csv file located same with db, you need to remove LOCAL in LOAD DATA INFILE, or you will get the error
The used command is not allowed with this MySQL version
This went a little weird for me, from one day to the next one the script that have been working since days just stop working. There wasn´t a newer version of mysql or any kind of upgrade but I was getting the same error, so I give a last try to the CSV file and notice that the end of lines were using \n instead of the expected ( per my script ) \r\n so I save it with the right EOL and run the script again without any trouble.
I think is kind of odd for mysql to tell me The used command is not allowed with this MySQL version since the reason was completely different.
My working command looks like this:
LOAD DATA LOCAL INFILE 'file-name' IGNORE INTO TABLE table-name CHARACTER SET latin1 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES.
I used below method, which doesn't require any change in config, tested on mysql-5.5.51-winx64 and 5.5.50-MariaDB:
put 'load data...' in .sql file (ex: LoadTableName.sql)
LOAD DATA INFILE 'D:\\Work\\TableRecords.csv' INTO TABLE tbl1 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (col1,col2);
then:
mysql -uroot -pStr0ngP@ss -Ddatabasename -e "source D:\Work\LoadTableName.sql"
In case if Mysql 5.7 you can use "show global variables like "local_infile" ;" which will give the local infile status ,You can turn it on using "set global local_infile=ON ; ".
Ok, something odd is happening here. To make this work, do NOT need to make any configuration changes in /etc/mysql/my.cnf . All you need to do is to restart the current mysql service in terminal:
sudo service mysql restart
Then if I want to "recreate" the bug, I simply restart the apache service:
sudo service apache2 restart
Which can then be fixed again by entering the following command:
sudo service mysql restart
So, it appears that the apache2 is doing something to not allow this feature when it starts up (which is then reversed/corrected if restart the mysql service).
Valid in Debian based distributions.
service mysqld restart
service httpd restart
Valid in RedHat based distributions
For those of you looking for answers to make LOAD DATA LOCAL
INFILE work like me, this might probably work. Well it worked for me, so here it goes. Install percona
as your mysql server and client by following the steps from the link. A password will be prompted for during the installation, so provide one that you'll remember and use it later. One the installation is done, reboot your system and test if the server is up and running by going to the terminal
and typing mysql -u root -p
and then the password. Try running the command LOAD DATA LOCAL INFILE
now.. Hope it works :)
BTW I was working on Rails 2.3 with Ruby 1.9.3 on Ubuntu 12.04.
All: Evidently this is working as designed. Please see new ref man dated 2019-7-23, Section 6.1.6, Security Issues with LOAD DATA LOCAL.
참고 URL : https://stackoverflow.com/questions/10762239/mysql-enable-load-data-local-infile
'Programming' 카테고리의 다른 글
공백이있는 jquery ID (0) | 2020.07.16 |
---|---|
두 날짜 사이의 월 차이 계산 (0) | 2020.07.16 |
가로 LinearLayout의 오른쪽 맞춤 버튼 (0) | 2020.07.16 |
Android : 가로 모드 용 대체 레이아웃 XML (0) | 2020.07.16 |
ImageButton에 텍스트를 표시하는 방법? (0) | 2020.07.16 |