mysql中的数据导入,导出

作用:

    把文件系统中内容导入到数据库中

语法格式:

    load data infile "文件名"

    into table 表名

    fileds terminated by "分隔符"

    lines terminated by "\n";

将socretable.csv导入到数据库:(socretable.csv是我已有文件)

    在数据库中创建对应的表

        create table score(
        id int, 
        name varchar(15), 
        score float, 
        thnumber char(11), 
        class char(7)
        )character set utf8;

    执行数据导入:

        查看搜索路径

            show variables like "secure_file_priv";
            ## /var/lib/mysql-files

        拷贝文件

            sudo cp /home/tarena/aid1807/mysql/day03/scoreTable.csv /var/lib/mysql-files

        执行数据导入

            load data infile "/var/lib/mysql-files/scoreTable.csv"
            into table score
            fields terminated by ","
            lines terminated by "\n";

    数据导出:

        把数据库表的记录导出到系统文件中:

            select ... from 表名
            into outfile "文件名"
            fileds terminated by "分隔符"
            lines terminated by "\n";

    查看,更改文件权限:

        ls -l score.txt

            -  rw-rw-r--  tarena tarena
                          所有者  所属组

            r(4): 读  w(2): 写  x(1):可执行

            rw-:可读可写,所有者权限

            rw-:同组其他用户文件

            r--:其他组的用户权限

        chmod 777 socre.txt
        chmod 740 socre.txt

    表的复制:

        语法:

            create table 表名 select ... from 表名 where 条件;

        示例:

            复制MOSHOU.sanguo表,sanguo2

            create table MOSHOU.sanguo2 select * from MOSHOU.sanguo;

    复制表结构:

        语法:

			create table 表名 select ... from 表名 where false;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值