MySQL使用shell命令执行sql
mysql -u${用户名} -p -e"SQL语句"; # 确认之后输入密码即可
下面举个例子:
[root@ecs-s3-large-2-linux-20200627183241 ~]# mysql -uzhoujl -p -e"show processlist";
Enter password:
+----+--------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+--------+-----------+------+---------+------+----------+------------------+
| 20 | zhoujl | localhost | NULL | Query | 0 | starting | show processlist |
+----+--------+-----------+------+---------+------+----------+------------------+
[root@ecs-s3-large-2-linux-20200627183241 ~]#