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;

猜你喜欢

转载自blog.csdn.net/weixin_43929852/article/details/86416692
今日推荐