无法通过 sh 连接到 mysql

时间:2021-01-08 03:29:43

标签: mysql

  1. 在命令行中,运行以下命令:

    /usr/bin/sudo mysql -u root -S /mnt/storagePool-1/storageSpace-1/.mysql/mysql3307/mysqld3307.sock

连接成功

root@U-NAS:~# /usr/bin/sudo mysql -u root -S /mnt/storagePool-1/storageSpace-1/.mysql/mysql3307/mysqld3307.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.31-log MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> 

但是无法通过sh脚本连接到mysql

sh 脚本:

#!/bin/sh
/usr/bin/sudo mysql -u root -S /mnt/storagePool-1/storageSpace-1/.mysql/mysql3307/mysqld3307.sock <<EOF
flush privileges;
create database if not exists testaa CHARACTER SET utf8 COLLATE utf8_general_ci;
quit
EOF
exit 0

创建数据库testaa不成功

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

0 个答案:

没有答案