Friends who have studied SQL Server or Oracle will know that a sql script is a collection of sql statements containing one or more sql commands. We can put these sql scripts in a text file (we call it a "sql script file"), Then execute this sql script file through the relevant commands. The basic steps are as follows:
1. Create a sql script file, such as the following sql statement, copy them to Notepad, and then save it as a sql suffix file.
c-- phpMyAdmin SQL Dump -- version 2.10.0.2 -- http://www.phpmyadmin.net -- -- 主机: localhost -- 生成日期: 2007 年 10 月 27 日 06:38 -- 服务器版本: 5.0.37 -- PHP 版本: 5.2.1 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- 数据库: `votesystem` -- CREATE DATABASE `votesystem` DEFAULT CHARACTER SET latin1 COLLATElatin1_general_ci; USE `votesystem`; -- -------------------------------------------------------- -- -- 表的结构 `admin` -- CREATE TABLE `admin` ( `username` char(20) NOT NULL default '', `passwd` char(20) NOT NULL default '', PRIMARY KEY (`username`) ) ENGINE=MyISAM DEFAULT CHARSET=gb2312; -- -- 导出表中的数据 `admin` -- INSERT INTO `admin` VALUES ('admin', 'admin'); -- -------------------------------------------------------- -- -- 表的结构 `voteitem` -- CREATE TABLE `voteitem` ( `voteitem_id` smallint(5) unsigned NOT NULL auto_increment, `vote_id` smallint(5) unsigned NOT NULL default '0', `vote_item` varchar(100) NOT NULL default '', `vote_count` smallint(5) unsigned NOT NULL default '0', PRIMARY KEY (`voteitem_id`) ) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=34 ; -- -- 导出表中的数据 `voteitem` -- INSERT INTO `voteitem` VALUES (25, 6, 'perl', 10); INSERT INTO `voteitem` VALUES (24, 6, 'python', 20); INSERT INTO `voteitem` VALUES (23, 6, 'c++', 20); INSERT INTO `voteitem` VALUES (22, 6, 'c', 15); INSERT INTO `voteitem` VALUES (21, 6, 'php', 25); INSERT INTO `voteitem` VALUES (29, 6, 'shell', 5); INSERT INTO `voteitem` VALUES (28, 6, 'asm', 5); INSERT INTO `voteitem` VALUES (27, 6, 'java', 3); INSERT INTO `voteitem` VALUES (26, 6, 'c#', 4); INSERT INTO `voteitem` VALUES (33, 7, 'Mac OS', 60); INSERT INTO `voteitem` VALUES (32, 7, 'OS/2', 5); INSERT INTO `voteitem` VALUES (31, 7, 'Windows', 50); INSERT INTO `voteitem` VALUES (30, 7, 'Linux', 51); -- -------------------------------------------------------- -- -- 表的结构 `votemain` -- CREATE TABLE `votemain` ( `vote_id` smallint(5) unsigned NOT NULL auto_increment, `vote_name` varchar(100) NOT NULL default '', `vote_time` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`vote_id`) ) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=8 ; -- -- 导出表中的数据 `votemain` -- INSERT INTO `votemain` VALUES (7, '你最喜欢的系统', '2007-10-26 14:10:13'); INSERT INTO `votemain` VALUES (6, '你最喜欢的语言', '2007-10-26 14:09:15');
2. Use the command to execute the sql script file
Method 1, use the cmd command under Windows (or Unix or Linux console) Note: Method 2, enter the MySQL console (such as: MySQL 5.5 Command Line Client), use the source command to execute
[Mysql bin directory] mysql –u username –p password –D database C:MySQLbinmysql –uroot –p123456 -Dtest
A. If the use database is used in the sql script file, Then the -D database option can be ignored
B. If the [Mysql bin directory] contains spaces, you need to use "" to include it, such as: "C:Program FilesMySQLbinmysql" –u username –p password –D databaseC. If sql does not have a statement to create a database, and the database does not exist in database management, you must first create an empty database with a command.
Mysql>source [full path name of sql script file] or Mysql>. [full path name of sql script file], Example:
source C:test.sql or . C:test.sql
Open the MySQL Command Line Client, enter the database password to log in, and then use the source command or .

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment