Home > Database > Mysql Tutorial > Shell script to operate mysql database

Shell script to operate mysql database

WBOY
Release: 2023-05-31 11:41:21
forward
1020 people have browsed it

Create table statement

  =============================================

  学生表:Student(Sno,Sname,Ssex,Sage,Sdept)

  ------(学号-主键,姓名,性别,年龄,所在系)

  =============================================

  create table student(

  Sno int(10) NOT NULL COMMENT '学号',

  Sname varchar(16) NOT NULL COMMENT '姓名',

  Ssex char(2) NOT NULL COMMENT '性别',

  Sage tinyint(2) NOT NULL default '0' COMMENT '学生年龄',

  Sdept varchar(16) default NULL COMMENT '学生所在系别',

  PRIMARY KEY (Sno)

  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Copy after login

Batch insert data script

  #!/bin/bash  #create by oldboy 20110319  #qq:31333741  MysqlLogin="mysql -uroot -poldboy" #→定义登陆mysql的命令,方便下文使用  #MysqlLogin="mysql -uroot -poldboy -S /data/3306/mysql.sock" #此行适合单机多实例数据库的方式  i=1

  while true #→true表示永远为真  do  ${MysqlLogin} -e "insert into test.student values ("$i",'oldboy"$i"','m','21','computer"$i"');"  #${MysqlLogin} -e "insert into oldboy.student values ("$i",'oldboy"$i"','m','21','computer"$i"');"  #如果是多张表可以同时插入多张表,我这里给出的例子,是插入不同的记录,可以用于做各种小测试,比较适合各类初级不会mysql存储过程的运维人员。  ((i++))

  sleep 2;

  done
Copy after login

The above is the detailed content of Shell script to operate mysql database. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template