mysql insert can't with select into outfile?

2019-09-04 08:18发布

问题:

mysql> insert into helpme set user=(select 0x616361 into outfile 'c://windows//temp//test.ini');
Database changed

mysql> select * from helpme;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+
| user                                                                                                                                                                                                                                    | id    |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+
| a                                                                                                                                                                                                                                       |     1 |                                                                                                                                                                                                                                  | 37833 |
| aca                                                                                                                                                                                                                                     | 37834 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------+
2 rows in set

why user is aca?and can't find the file (c://windows//temp//test.ini)?

回答1:

SELECT … INTO … can’t be used in a sub-query:

An INTO clause should not be used in a nested SELECT because such a SELECT must return its result to the outer context.

That’s why MySQL chose to return the value instead of writing it into file.



标签: mysql insert