发布网友 发布时间:2022-05-03 03:20
共3个回答
懂视网 时间:2022-05-03 07:41
#!/usr/bin/env bash
[[ -n $DEBUG ]] && set -x
set -eou pipefail
useage(){
cat <<HELP
USAGE:
sqldemo.sh
HELP
}
exit_err() {
echo >&2 "${1}"
exit 1
}
if [ $# -lt 0 ];then
useage
exit 1
fi
DEMODIR=$(mktemp -d)
echo "${DEMODIR}"
cd "${DEMODIR}"
cat > "${DEMODIR}"/demo.sql <<EOF
CREATE DATABASE IF NOT EXISTS demo;
use demo;
CREATE TABLE IF NOT EXISTS demo_data (
id INT NOT NULL AUTO_INCREMENT,
data VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
DROP PROCEDURE IF EXISTS init_data;
DELIMITER //
CREATE PROCEDURE init_data(IN number INT,OUT total INT)
BEGIN
DECLARE i INT DEFAULT 1;
SET @tmp_id=(SELECT id FROM demo_data LIMIT 1);
IF (@tmp_id IS NULL) THEN
WHILE (i<=number) DO
INSERT INTO demo_data VALUES(i,i);
SET i=i+1;
END WHILE;
END IF;
SELECT COUNT(*) FROM demo_data INTO total;
END //
DELIMITER ;
CALL init_data(1000, @total);
SELECT @total;
DROP TABLE IF EXISTS demo;
CREATE TEMPORARY TABLE demo AS (
SELECT * FROM demo_data
);
EOF
mysql -u root -h 127.0.0.1 -p
sqldemo
source ./demo.sql
如何快速新建sql的demo环境?
标签:如何快速 values eof bug efault amp 如何 deb 脚本
热心网友 时间:2022-05-03 04:49
在dos命令中进去数据库后的执行语句为。热心网友 时间:2022-05-03 06:07
网上下一个mysql,装在电脑上,就行