Khi cố gắng tải dữ liệu tệp cục bộ vào bảng MySQL của bạn, bạn có thể thấy lỗi nói rằng The used command is not allowed with this MySQL version
Ví dụ: tôi muốn tải tệp infile.txt
vào bảng có tên students
với dữ liệu sau
Sarah Math 9
Christ English 7
Natalia Math 6
Khi tôi chạy câu lệnh
mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
0, MySQL sẽ báo lỗi saumysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
Lỗi này xảy ra do tải dữ liệu từ tệp cục bộ hiện đã bị tắt theo mặc định
Lưu ý rằng khi bạn cập nhật lên phiên bản MySQL mới nhất, thông báo lỗi có thể đã được thay đổi thành thông báo mô tả rõ hơn như sau
mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 3948 [42000]: Loading local data is disabled;
this must be enabled on both the client and server sides
Cả hai lỗi có thể được giải quyết theo cùng một cách
Bạn cần cho phép tải tệp cục bộ bằng cách bật tính năng này từ cả phía máy khách và máy chủ. Hãy học cách làm điều đó tiếp theo
Cho phép tải dữ liệu cục bộ trên máy chủ và máy khách MySQL
Trước tiên, bạn cần kích hoạt tải dữ liệu cục bộ từ phía máy chủ bằng cách đặt giá trị biến toàn cục
mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
1 thành mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
2Bạn có thể tìm biến bằng câu lệnh
mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
3 như hình bên dướiSHOW VARIABLES LIKE 'local_infile';
-- The response:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | OFF |
+---------------+-------+
Trong trường hợp của mình, biến
mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
1 vẫn là mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
5 nên mình cần sử dụng câu lệnh mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
6 để biến nó thành mysql> LOAD DATA LOCAL INFILE './infile.txt' INTO TABLE students;
ERROR 1148 [42000]: The used command is not allowed with this MySQL version
2 như sau