MySQL console executes .sql script file

Write a .sql script file with notepad++:

 1 drop database if exists library;
 2 create database library default character set utf8;
 3 use library;
 4 
 5 create table user(
 6     id int(11) not null auto_increment,
 7     name varchar(255) default null,
 8     password varchar(255) default null,
 9     primary key (id)
10 )engine=innodb default charset=utf8;

Save it to the Sql folder of the F drive and name it createTable.sql

Open the console that comes with MySQL, enter the password of the root account, and after successful login, execute the command:   

1 source F:\Sql\createTable.sql  //Note that the absolute path is used here, and there is no need to add a semicolon at the end

As shown in the figure, the execution is successful, you can execute the following command to view 

1 show tables;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325016967&siteId=291194637