前几天有同事问,不通过navicat怎么把查询数据导出到excel表中,今天它来了,下面是具体的脚本。
cat /home/1.sh
#!/bin/bash
#数据库的host地址
DB_HOST='X.X.X.X'
#用户
DB_USER='root'
#密码
DB_PASS='123123'
# 输出文件
OUTPUT_FILE='/home/mysql_result.csv'
# 连接到数据库并执行命令
mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "
show variables like '%validate_password%';
use ceshi;
select * from Customers;
show variables like '%password%';
show variables like '%val%';
SHOW GLOBAL VARIABLES LIKE '%password%';
select user, authentication_string from mysql.user where length(authentication_string)=0 or authentication_string is null;
show databases;
use mysql;
select * from mysql.user;
select * from mysql.db;
select * from mysql.tables_priv;
select * from mysql.procs_priv;
select version();
select * from mysql.event;
show variables like '%event_sche%';
show variables like '%schedule%';
show events;
" > "$OUTPUT_FILE"
只需要替换标红处,就可以完成查询命令的输出。