简体   繁体   中英

importing text files within MySQL

I'm looking for this solution for an hour in the web and books but I can't find it anywhere.

I've made a MySQL script via Emacs, but I would like to implement it to create a database by importing or including the script (instead of copy-paste it into the terminal).

PS: I'm not looking for importing values to an existing database; I'm really looking to implement a script, like for example:

create database store;
create table user(
        ID integer not null auto_increment primary key,
        'FIRST NAME' varchar(20) not null,
        'LAST NAME' varchar(20) not null,
        AGE tinyint not null,
        LOCATION text not null);

-- inserting virtual users
insert into user('FIRST NAME', 'LAST NAME', AGE, LOCATION) values
        ('John', 'Thomas', 21, 'EN'),
        ('Richard', 'Randy', 51, 'US');

How can I achieve that?

Save it to a file eg schema.sql and then run

mysql -u username -p < /path/to/schema.sql

With whatever hostname, authentication you normally use.

Explained in the manual

I tried like this and its working fine for me .

webelitetest   --- Database name

courses.sql   --- Sql File name

c:\xampp\mysql\bin\mysql -h localhost -u root -p webelitetest<C:/courses.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM