通过参数-e
[root@node1 ~]# mysql -uroot -p123456 -e "show databases" mysql: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ | employees | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ [root@node1 ~]# mysql -uroot -p123456 -e "select count(1) from employees.employees" mysql: [Warning] Using a password on the command line interface can be insecure. +----------+ | count(1) | +----------+ | 300024 | +----------+ [root@node1 ~]#
system + 系统shell命令,不需要分号
mysql> system date 2021年 11月 15日 星期一 00:36:50 EST mysql> system pwd /root mysql> system ls / app bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var mysql>