시도 :
파일 : 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 시도 정보.
다음을 시도해보십시오. 'UPDATE table1 SET \'trans \'= translit (dn);'. [9.2.4 함수명 구문 분석 및 분석] (https://dev.mysql.com/doc/refman/5.7/en/function-resolution.html)을 참조하십시오. – wchiquito
그냥 시도해 봤어 .. (오류 1064 (42000) at line 23 : SQL 문법에 오류가있다 : '= translit (dn)'근처에서 사용할 올바른 구문을 보려면 MySQL 서버 버전에 해당하는 설명서를 확인하십시오. line 1 –
이 방법으로 작동합니다. UPDATE table1 SET table1.trans = translit (table1.dn); –