2017-05-21 1 views
0

나는이 쉘 스크립트를 실행하는거야 내가있는 행에 오류가 발생, 출력에MySQL 사용자 정의 함수는

#!/bin/bash -x 
mysql -u username -password base1 << EOF 
UPDATE table1 SET `trans` = translit (dn); 

을 내 사용자 정의 함수 translit. 다른 모든 MySQL 명령은 성공적으로 완료됩니다. phpMyAdmin 아래에서 언급 한 명령이 올바르게 실행됩니다. 기능 translit이 올바르게 정의되었습니다.

+0

다음을 시도해보십시오. 'UPDATE table1 SET \'trans \'= translit (dn);'. [9.2.4 함수명 구문 분석 및 분석] (https://dev.mysql.com/doc/refman/5.7/en/function-resolution.html)을 참조하십시오. – wchiquito

+0

그냥 시도해 봤어 .. (오류 1064 (42000) at line 23 : SQL 문법에 오류가있다 : '= translit (dn)'근처에서 사용할 올바른 구문을 보려면 MySQL 서버 버전에 해당하는 설명서를 확인하십시오. line 1 –

+0

이 방법으로 작동합니다. UPDATE table1 SET table1.trans = translit (table1.dn); –

답변

0

여기 문서의 역 인용 부호는 명령 대체로 해석되어 mysql이 실행되기 전에 쉘에 의해 처리됩니다. 쉘 처리에서 here 문서의 내용을 보호하기 위해 분리 문자를 인용하십시오.

#!/bin/bash -x 
mysql -u username -password base1 << 'EOF' 
UPDATE table1 SET `trans` = translit (dn); 
EOF 

(참고 :. 나는 역 인용 부호가 실제로 작은 따옴표 수 여부, 또는 인용하면 것은 여기에 필요하는 경우는 MySQL이 알고에 충분히 익숙하지 않은거야)

0

시도 :

파일 : myscript.sh

#!/bin/bash -x 
mysql -u username -p -s << 'EOF' 
USE `base1`; 
SELECT `dn`, `trans` 
FROM `table1`; 

UPDATE `table1` 
SET `trans` = `translit`(`dn`); 

SELECT CONCAT(REPEAT('*', 15), ' UPDATE ', REPEAT('*', 15)); 

SELECT `dn`, `trans` 
FROM `table1`; 
EOF 
$ mysql -u username -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 1 
Server version: 5.7.11 

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 

Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

mysql> DROP DATABASE IF EXISTS `base1`; 
Query OK, 1 row affected (0.00 sec) 

mysql> CREATE DATABASE IF NOT EXISTS `base1`; 
Query OK, 1 row affected (0.00 sec) 

mysql> USE `base1`; 
Database changed 

mysql> DROP FUNCTION IF EXISTS `translit`; 
Query OK, 0 rows affected, 1 warning (0.00 sec) 

mysql> DROP TABLE IF EXISTS `table1`; 
Query OK, 0 rows affected, 1 warning (0.00 sec) 

mysql> CREATE TABLE IF NOT EXISTS `table1` (
    -> `dn` VARCHAR(30) NOT NULL, 
    -> `trans` VARCHAR(30) 
    ->); 
Query OK, 0 rows affected (0.00 sec) 

mysql> INSERT INTO `table1` 
    -> (`dn`) 
    -> VALUES 
    -> ('Lorem Ipsum is simply dummy'), 
    -> ('text of the printing'), 
    -> ('and typesetting industry'); 
Query OK, 3 rows affected (0.00 sec) 
Records: 3 Duplicates: 0 Warnings: 0 

mysql> CREATE FUNCTION `translit`(`_dn` VARCHAR(30)) 
    -> RETURNS VARCHAR(30) DETERMINISTIC 
    -> RETURN REVERSE(`_dn`); 
Query OK, 0 rows affected (0.00 sec) 

mysql> \! ./myscript.sh 
+ mysql -u root -p -s 
Enter password: 
Lorem Ipsum is simply dummy NULL 
text of the printing NULL 
and typesetting industry NULL 
*************** UPDATE *************** 
Lorem Ipsum is simply dummy ymmud ylpmis si muspI meroL 
text of the printing gnitnirp eht fo txet 
and typesetting industry yrtsudni gnittesepyt dna 
mysql> 

sensiti 노출하지 않는 4.6.6 mysql_config_editor — MySQL Configuration Utility 시도 정보.

관련 문제