Linux命令行执行MYSQL语句

[root@localhost ~]# /usr/bin/mysql -N -e "show databases;use centreon2;select count(*) from host;source /home/centreon2.sql" 
+--------------------+
| information_schema | 
|          centreon2 | 
|  centreon2_storage | 
|              mysql | 
|             nagios | 
|               test | 
+--------------------+
+------+
| 1899 | 


今天试验了 非常好用


/usr/bin/mysql -h$HOSTADDRESS$ -u$ARG1$ -p$ARG2$ -N -e $ARG3$


ARG1 : user such as root
ARG2 : pws such as 123456
ARG3 : sql command such as  "use mysql; show tables;"

你可能感兴趣的:(Linux运维)