美文网首页
终端操作数据库

终端操作数据库

作者: GA_ | 来源:发表于2017-03-14 16:24 被阅读14次

http://www.cnblogs.com/fly1988happy/archive/2011/12/15/2288554.html

// 终端登录mysql 
./mysql -h localhost -p -u jianan

// root登录
houjianandeMacBook-Pro:bin houjianan$ ./mysql -h localhost -p -u root
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.1.13-MariaDB Source distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

// 创建数据库 db001
MariaDB [(none)]> create database db001;
Query OK, 1 row affected (0.00 sec)

// 展示所有数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| db001              |
| db11               |
| db131              |
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
| testData           |
+--------------------+
// 使用数据库db11
MariaDB [(none)]> use db11;
Database changed
// 使用数据库db001
MariaDB [(none)]> use db001;
Database changed

// 展示数据库db001中的所欲表
MariaDB [db001]> show tables;
+-----------------+
| Tables_in_db001 |
+-----------------+
| person          |
+-----------------+
1 row in set (0.00 sec)
//展示标的详情
MariaDB [db001]> desc person;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| age   | int(11)          | YES  |     | NULL    |                |
| name  | text             | YES  |     | NULL    |                |
| des   | text             | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
-增-
// 往表person中插入字段id和name对应值分别为5和jianan
MariaDB [db001]> insert into person (id, name) values (5, 'jianan');
Query OK, 1 row affected (0.01 sec)

// 往表person中插入字段id, name, age, des对应的值为6, 'jianan', 27, '腿很长'
MariaDB [db001]> insert into person (id, name, age, des) values (6, 'jianan', 27, '腿很长');
Query OK, 1 row affected, 1 warning (0.00 sec)

// 查看表里的内容
MariaDB [db001]> select * from person;
+----+------+--------+------+
| id | age  | name   | des  |
+----+------+--------+------+
|  2 | NULL | NULL   | NULL |
|  3 |   27 | NULL   | NULL |
|  5 | NULL | jianan | NULL |
|  6 |   27 | jianan | ???  |
+----+------+--------+------+
4 rows in set (0.04 sec)

// 往表person中插入字段id, name, age, des对应的值为6, 'jianan', 27, '腿很长'
MariaDB [db001]> insert into person values (7, 'jianan', 27, '腿很长');
Query OK, 1 row affected, 2 warnings (0.01 sec)

// 往表person中插入 两组 字段name, age对应的值为'jianan001', 28和'jianan002', 29
MariaDB [db001]> insert into person (name, age) values ('jianan001', 28), ('jianan002', 29);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

// 查看表里的内容
MariaDB [db001]> select * from person;
+----+------+-----------+------+
| id | age  | name      | des  |
+----+------+-----------+------+
|  2 | NULL | NULL      | NULL |
|  3 |   27 | NULL      | NULL |
|  5 | NULL | jianan    | NULL |
|  6 |   27 | jianan    | ???  |
|  7 |    0 | 27        | ???  |
|  8 |   28 | jianan001 | NULL |
|  9 |   29 | jianan002 | NULL |
+----+------+-----------+------+
7 rows in set (0.00 sec)

MariaDB [db001]>  
-改-
MariaDB [db001]> select * from person;
+----+------+-----------+------+
| id | age  | name      | des  |
+----+------+-----------+------+
|  2 | NULL | NULL      | NULL |
|  3 |   27 | NULL      | NULL |
|  5 | NULL | jianan    | NULL |
|  6 |   27 | jianan    | ???  |
|  7 |    0 | 27        | ???  |
|  8 |   28 | jianan001 | NULL |
|  9 |   29 | jianan002 | NULL |
+----+------+-----------+------+
7 rows in set (0.00 sec)

// 修改表中id=2的用户name和age
MariaDB [db001]> update person set
    -> name = 'jianan',
    -> age = 30
    -> where id = 2;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
// 查看表里的内容
MariaDB [db001]> select * from person
    -> ;
+----+------+-----------+------+
| id | age  | name      | des  |
+----+------+-----------+------+
|  2 |   30 | jianan    | NULL |
|  3 |   27 | NULL      | NULL |
|  5 | NULL | jianan    | NULL |
|  6 |   27 | jianan    | ???  |
|  7 |    0 | 27        | ???  |
|  8 |   28 | jianan001 | NULL |
|  9 |   29 | jianan002 | NULL |
+----+------+-----------+------+
7 rows in set (0.01 sec)

-删-
// 删除id=6在表中的内容
MariaDB [db001]> delete from person
    -> where id = 6;
Query OK, 1 row affected (0.00 sec)

-选-
// 查看表里的内容
MariaDB [db001]> select * from person;
+----+------+--------+------+
| id | age  | name   | des  |
+----+------+--------+------+
|  2 |   30 | jianan | NULL |
|  3 |   27 | jianan | NULL |
|  5 | NULL | jianan | NULL |
|  7 |    0 | jianan | ???  |
|  8 |   28 | jianan | NULL |
|  9 |   29 | jianan | NULL |
+----+------+--------+------+
6 rows in set (0.00 sec)
// 查看表里的字段age和name
MariaDB [db001]> select age, name from person;
+------+--------+
| age  | name   |
+------+--------+
|   30 | jianan |
|   27 | jianan |
| NULL | jianan |
|    0 | jianan |
|   28 | jianan |
|   29 | jianan |
+------+--------+
6 rows in set (0.00 sec)
// 查看表里id=3中id和age的字段
MariaDB [db001]> select id, age from person where id = 3;
+----+------+
| id | age  |
+----+------+
|  3 |   27 |
+----+------+
1 row in set (0.01 sec)
// 查看表里id大于等于4中age字段
MariaDB [db001]> select age from person
    -> where id >= 4;
+-----+
| age |
+-----+
|   5 |
|   7 |
|   8 |
|   9 |
+-----+
4 rows in set (0.01 sec)

-表创建-
MariaDB [db001]> show tables;
+-----------------+
| Tables_in_db001 |
+-----------------+
| person          |
+-----------------+
1 row in set (0.01 sec)
// 创建表person01,id是自动增长的主键,长度20的title字段,长度100的content字段
MariaDB [db001]> create table person01 (
    -> id int primary key auto_increment,
    -> title varchar(20),
    -> content varchar (100)
    -> )charset utf8;
Query OK, 0 rows affected (0.24 sec)

MariaDB [db001]> show tables;
+-----------------+
| Tables_in_db001 |
+-----------------+
| person          |
| person01        |
+-----------------+
2 rows in set (0.00 sec)

终端创建完数据库 下图红框处刷新


6FB189E0-DED0-4EFA-936F-C1B660A6D784.png

相关文章

  • [转] mac os 终端对数据库的操作(自己留用)

    mac os 终端对数据库的操作

  • MySQL - 设置字符集

    前情提要 操作系统:CentOS7 数据库:MySQL-5.7.19 连接终端:SecureCRT7 显示数据库信...

  • mysql

    进入数据库操作/连接数据库 在终端进入mysql安装目录的bin 目录下,输入mysql -h localhost...

  • MySQL常用语句大全(纯干货,无废话)

    数据库用户名: root密码: mysql -- 数据表的操作 终端备份 扩展阅读: https:/...

  • mac Navicat创建本地数据库

    一、关闭本地MySQL(包括其他数据库终端) 1、进入mysql操作目录:(cd /usr/local/mysql...

  • SQLite学习(一)

    使用shell操作数据库 一、创建数据库 让我们从创建一个称为 test.db 的数据库开始,进入终端,输入命令:...

  • MySQL终端操作

    常用终端命令 登录数据库: 登出数据库: 以下操作均在mysql登录成功状态下 1.显示数据库版本: 2.显示数据...

  • MySQL快速入门

    登入、退出操作 终端登入mysql 重置mysql初始密码 退出mysql 基本操作 查询已创建的数据库 创建数据...

  • 数据分析之MySQL学习笔记

    MySQL 学习笔记 一、使用终端操作数据库 (一)、基本语句 1、登录数据库服务器 2、查询数据库服务器中所有的...

  • MySQL中interactive_timeout和wait_t

    在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误: ERR...

网友评论

      本文标题:终端操作数据库

      本文链接:https://www.haomeiwen.com/subject/wqjhnttx.html