C:\Users\Mr.Black>mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;
+----------------------+
| Database             |
+----------------------+
| information_schema   |
| a_stock              |
| allstuid             |
| dagang1              |
| dagang2              |
| duxue                |
| mxonline             |
| mysql                |
| performance_schema   |
| rail_freightdb       |
| shijiazhuangdianping |
| studentdb            |
| sys                  |
| test2                |
| xicai                |
+----------------------+
15 rows in set (0.06 sec)

mysql> create database us_pwd;
Query OK, 1 row affected (0.02 sec)

mysql> show databases;
+----------------------+
| Database             |
+----------------------+
| information_schema   |
| a_stock              |
| allstuid             |
| dagang1              |
| dagang2              |
| duxue                |
| mxonline             |
| mysql                |
| performance_schema   |
| rail_freightdb       |
| shijiazhuangdianping |
| studentdb            |
| sys                  |
| test2                |
| us_pwd               |
| xicai                |
+----------------------+
16 rows in set (0.00 sec)

-----------------------------------------------

选择数据库

mysql> use us_pwd;
Database changed

------------------------------------------------

设置使用的字符集

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

-------------------------------------------------

建表

mysql> create table user_pwd( user_id int unsigned primary key not null auto_increment, name varchar(20) not null, password varchar(20) not null);
Query OK, 0 rows affected (0.37 sec)

-----------------------------------------------

读取数据表的信息

mysql> select * from user_pwd;
Empty set (0.00 sec)

-----------------------------------------------

向表中插入数据

mysql> insert into user_pwd (name,password) values ("chen","helloword!");
Query OK, 1 row affected (0.09 sec)

mysql> select * from user_pwd;
+---------+------+------------+
| user_id | name | password   |
+---------+------+------------+
|       1 | chen | helloword! |
+---------+------+------------+
1 row in set (0.00 sec)

mysql> insert into user_pwd (user_id, name,password) values (2,"wang","helloword!");
Query OK, 1 row affected (0.09 sec)

mysql> insert into user_pwd  values (3,"yang","123456");
Query OK, 1 row affected (0.08 sec)

mysql> insert into user_pwd  values ("liu","root123");  # 错误!
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into user_pwd  values (4,"liu","root123");
Query OK, 1 row affected (0.08 sec)

mysql> insert into user_pwd (name,password) values ("alice","p@ssw0rd!");
Query OK, 1 row affected (0.12 sec)

mysql> select * from user_pwd;
+---------+-------+------------+
| user_id | name  | password   |
+---------+-------+------------+
|       1 | chen  | helloword! |
|       2 | wang  | helloword! |
|       3 | yang  | 123456     |
|       4 | liu   | root123    |
|       5 | alice | p@ssw0rd!  |
+---------+-------+------------+
5 rows in set (0.00 sec)

------------------------------------------------

更新数据

mysql> update user_pwd set name="wang2", password="abcd123" where user_id="2";
Query OK, 1 row affected (0.08 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from user_pwd;
+---------+-------+------------+
| user_id | name  | password   |
+---------+-------+------------+
|       1 | chen  | helloword! |
|       2 | wang2 | abcd123    |
|       3 | yang  | 123456     |
|       4 | liu   | root123    |
|       5 | alice | p@ssw0rd!  |
+---------+-------+------------+
5 rows in set (0.00 sec)
-----------------------------------------------

删除行数据

mysql> delete from user_pwd where name="yang" and password="root123";  # 这里and是且,要同时满足两个,而不是把含这俩的都删掉
Query OK, 0 rows affected (0.00 sec)

mysql> delete from user_pwd where name="yang" or password="root123";  #改成or就好了
Query OK, 2 rows affected (0.05 sec)

mysql> select * from user_pwd;
+---------+-------+------------+
| user_id | name  | password   |
+---------+-------+------------+
|       1 | chen  | helloword! |
|       2 | wang2 | abcd123    |
|       5 | alice | p@ssw0rd!  |
+---------+-------+------------+
3 rows in set (0.00 sec)

------------------------------------------------

删除一列

mysql> alter table user_pwd drop column name;
Query OK, 0 rows affected (0.90 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from user_pwd;
+---------+------------+
| user_id | password   |
+---------+------------+
|       1 | helloword! |
|       2 | abcd123    |
|       5 | p@ssw0rd!  |
+---------+------------+
3 rows in set (0.00 sec)

-----------------------------------------------

删除表里的数据

mysql> delete from user_pwd;
Query OK, 3 rows affected (0.05 sec)

mysql> create table user_pwd(user_id int unsigned primary key not null auto_increment,name varchar(20) not null,password varchar(20) not null);
ERROR 1050 (42S01): Table 'user_pwd' already exists  # 可以看到表并没有被删除

mysql> show tables;
+------------------+
| Tables_in_us_pwd |
+------------------+
| user_pwd         |
+------------------+
1 row in set (0.00 sec)

------------------------------------------------

删表

mysql> drop table if exists user_pwd;
Query OK, 0 rows affected (0.20 sec)

mysql> show tables;
Empty set (0.00 sec)

------------------------------------------------

删库

mysql> drop database us_pwd;
Query OK, 1 row affected (0.29 sec)

mysql> show databases;
+----------------------+
| Database             |
+----------------------+
| information_schema   |
| a_stock              |
| allstuid             |
| dagang1              |
| dagang2              |
| duxue                |
| mxonline             |
| mysql                |
| performance_schema   |
| rail_freightdb       |
| shijiazhuangdianping |
| studentdb            |
| sys                  |
| test2                |
| xicai                |
+----------------------+
15 rows in set (0.00 sec)

MySql 创建/删除数据库的更多相关文章

  1. mysql 创建++删除 数据库

    创建RUNOOB数据库,并设定编码集为utf8 CREATE DATABASE IF NOT EXISTS RUNOOB DEFAULT CHARSET utf8 COLLATE utf8_gener ...

  2. MySQL 创建删除和选择数据库

    使用 create 命令创建数据库,语法如下: CREATE DATABASE 数据库名; 删除数据库 drop database <数据库名>; 选择数据库 use 数据库名 Datab ...

  3. php 创建删除数据库

    <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, ...

  4. mysql创建/删除表的例子

    创建表 简单的方式 CREATE TABLE person ( number INT(11), name VARCHAR(255), birthday DATE ); 或者是 CREATE TABLE ...

  5. mysql创建的数据库在电脑什么位置?

    你可以在mysql 命令行里执行 show variables like '%datadir%'; 显示出你数据文件的路径,能找到以你创建的数据库的名字的文件夹了.

  6. mongodb的创建删除数据库

    1.创建数据库 use 命令 MongoDB use DATABASE_NAME 用于创建数据库.该命令将创建一个新的数据库,如果它不存在,否则将返回现有的数据库. 语法: use DATABASE  ...

  7. MongoDB自学------(2)创建删除数据库及集合

    一.创建数据库 二.查看所有数据库 三.删除数据库 四.创建集合 五.删除集合 六.集合用法介绍 1.创建集合 2.删除集合 下一篇链接:https://www.cnblogs.com/LinHuCh ...

  8. mysql 如何删除数据库中所有的表

    SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')FROM information_schema.tablesWHERE table_sch ...

  9. PHP MySQL Delete删除数据库中的数据

    PHP MySQL Delete DELETE 语句用于从数据库表中删除行. 删除数据库中的数据 DELETE FROM 语句用于从数据库表中删除记录. 语法 DELETE FROM table_na ...

随机推荐

  1. 1105 第K大的数(二分)

    1105 第K大的数 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 数组A和数组B,里面都有n个整数.数组C共有n^2个整数,分别是A[0] * B[0],A[0 ...

  2. 3N Numbers

    D - 3N Numbers Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Let N b ...

  3. jquery lazyload延迟加载技术的实现原理分析_jquery

    前言 懒加载技术(简称lazyload)并不是新技术,它是js程序员对网页性能优化的一种方案.lazyload的核心是按需加载.在大型网站中都有lazyload的身影,例如谷歌的图片搜索页,迅雷首页, ...

  4. 解决Raize日历控件显示的问题

    解决Raize日历控件显示的问题 近自己的程序被测试人员发现一个小问题,就是程序中的日历选择框,显示中的“星期一.星期二....”都显示成了“星.....”,我自己看了代码,原来是raize的控件问题 ...

  5. python构造wireshark可以解析的LTE空口数据

    Wireshark是可以解析LTE的空口数据.但是在wireshark的实现中,这些数据都是被封装到UDP报文中.然后根据wireshark的格式文件对LTE的数据加上头信息.头信息的定义参考附件pa ...

  6. comboBox绑定字典Dictionary 获取value中的值

    第一种 最简洁的方法 Dictionary<string, string> list = new Dictionary<string, string> { {"thi ...

  7. Android测试读写sd卡文件与写sd卡文件耗时

    测试从sd卡读1k大小的文件,再写1k大小的文件,由于处理耗时很短,所以循环500次,查看耗时:测试写1k大小的文件,直接在内存构造一个1k的buffer,将这个buffer直接写到文件,同样循环50 ...

  8. 如何修改Eclipse中的快捷键

    首先打开Eclipse,Windows->Preferences ↓ 进入Preferences界面后,选择General->Keys ↓ 接下来你就会看到: 接下来点击OK就可以生效了.

  9. Android摄像头测量尺(Advanced Ruler Pro)使用方法

    http://www.cnblogs.com/sinojelly/archive/2010/08/13/1799341.html Advanced Ruler Pro是一个Android手机应用程序, ...

  10. Oracle创建新用户并将某一用户的表导进来

    一.建立测试账号 进入sqlplus(以管理员身份) sqlplus / as sysdba; create user user1 identified by user1;  //创建用户名并指定密码 ...