博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL 创建新用户以及导入数据
阅读量:4705 次
发布时间:2019-06-10

本文共 2123 字,大约阅读时间需要 7 分钟。

新建用户

先登录进root用户,然后再利用root用户的权限进行创建用户操作

mysql> create user 'mrc'@'localhost' identified by '123456';

刷新授权:mysql> flush privileges;

为新用户分配权限:mysql> grant all privileges on car.* to mrc@localhost;

建表导入数据(txt)

  建立pet表:

  CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

 

  • 在电脑中准备一个pet.txt文件,里面包含想要导入到pet表的数据。(文件中一行代表一条数据,一条数据中的属性用Tab键隔开)
  • 向pet表载入pet.txt中的数据:
    1. mysql> LOAD DATA LOCAL INFILE 'E:\Desktop\pet.txt' INTO TABLE pet; ERROR 1148 (42000): The used command is not allowed with this MySQL version

      ERROR原因:服务器端,local_infile默认开启,客户端local_infile默认关闭,因此用的时候需要打开它

    2. mysql> SHOW VARIABLES like 'local_infile'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | local_infile | OFF | +---------------+-------+ 1 row in set, 1 warning (0.04 sec)

      开启local_infile:(开启后,再次执行SHOW VARIABLES like 'local_infile'会看到Value为ON)

    3. mysql> SET GLOBAL local_infile=ON;Query OK, 0 rows affected (0.00 sec)

      重新载入:

    4. mysql> LOAD DATA LOCAL INFILE 'E:\Desktop\pet.txt' INTO TABLE pet; ERROR 2 (HY000): File 'E:Desktoppet.txt' not found (OS errno 2 - No such file or directory)

      ERROR原因:路径应使用'/'   , 重新载入:

    5. mysql> LOAD DATA LOCAL INFILE 'E:/Desktop/pet.txt' INTO TABLE pet; Query OK, 8 rows affected, 7 warnings (0.02 sec) Records: 8 Deleted: 0 Skipped: 0 Warnings: 7  

      载入完毕,查看载入成功后的pet表:

    6. mysql> select * from pet;+----------+--------+---------+------+------------+------------+ | name | owner | species | sex | birth | death | +----------+--------+---------+------+------------+------------+ | Fluffy | Harold | cat | f | 1993-02-04 | 0000-00-00 | | Claws | Gwen | cat | m | 1994-03-17 | 0000-00-00 | | Buffy | Harold | dog | f | 1989-05-13 | 0000-00-00 | | Fang | Benny | dog | m | 1990-08-27 | 0000-00-00 | | Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 | | Chirpy | Gwen | bird | f | 1998-09-11 | 0000-00-00 | | Whistler | Gwen | bird | | 1997-12-09 | 0000-00-00 | | Slim | Benny | snake | m | 1996-04-29 | 0000-00-00 | +----------+--------+---------+------+------------+------------+ 8 rows in set (0.00 sec

 

转载于:https://www.cnblogs.com/dashuaiB/p/10725728.html

你可能感兴趣的文章
ASP.NET MVC 随想录——开始使用ASP.NET Identity,初级篇
查看>>
用纯JS实现双向数据绑定
查看>>
php 解决返回数据 数字 变成科学计数法后转换问题
查看>>
How-To-Secure-A-Linux-Server
查看>>
网络与多线程的设计例子
查看>>
ubuntu12.04 各种小问题及解决方案集锦【持续更新】
查看>>
如何更改silverlight datagrid header的背景
查看>>
Data Structure Binary Tree: Construct Full Binary Tree from given preorder and postorder traversals
查看>>
类和对象的系统函数和运算符
查看>>
Checkstyle
查看>>
go语言的数组
查看>>
【题解】士兵训练-C++
查看>>
C#设计模式(4)——抽象工厂模式
查看>>
高级基础知识 ObservableCollection 类
查看>>
20165101刘天野 2018-2019-2《网络对抗技术》Exp5 MSF基础应用
查看>>
LeetCode: Find Bottom Left Tree Value
查看>>
安装包签名
查看>>
流行的开源软件和技术
查看>>
iOS---去除url中的反斜扛
查看>>
qwq
查看>>