【问题标题】:importing text files within MySQL在 MySQL 中导入文本文件
【发布时间】:2013-11-08 11:34:38
【问题描述】:

我在网络和书籍中寻找这个解决方案一个小时,但我在任何地方都找不到。

我已经通过 Emacs 制作了一个 MySQL 脚本,但我想通过导入或包含脚本来实现它来创建数据库(而不是将其复制粘贴到终端中)。

PS:我不是在寻找将值导入现有数据库;我真的很想实现一个脚本,例如:

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');

我怎样才能做到这一点?

【问题讨论】:

    标签: php mysql text emacs


    【解决方案1】:

    将其保存到文件,例如 schema.sql,然后运行

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

    使用您通常使用的任何主机名进行身份验证。

    Explained in the manual

    【讨论】:

    • 非常感谢。就是这么简单!
    【解决方案2】:
    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
    

    【讨论】:

      猜你喜欢
      • 2017-07-03
      • 1970-01-01
      • 2013-07-24
      • 2015-05-04
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 2016-01-30
      • 2016-10-23
      相关资源
      最近更新 更多