MySql 创建/删除数据库
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)
最新文章
- iOS 跳转到App Store下载或评论
- 剑指offer题目1-10
- 2014年听写VOA50篇
- OpenCV学习(一)
- 转载:.NET Web开发技术简单整理
- java中的变量
- cocos2d-x环境搭建(win7+cocos2d-x-3.0)
- 用CSS画小猪佩奇,你就是下一个社会人!
- 551.学生出勤记录I
- C#:如何使方法过时,如何否决方法
- Mybatis(二)入门程序-通过id查找用户、模糊查找用户、添加用户、删除用户
- day07 元组类型 字典类型 集合
- 设置 IntelliJ IDEA 智能提醒时忽略大小写
- 剑指Offer 32. 把数组排成最小的数 (数组)
- 【mysql】---php链接数据库---【巷子】
- mail 发送email
- 买不到的数目|2018年蓝桥杯A组题解析第八题-fishers
- P问题,NP问题,NPC问题,NP-hard问题
- git 使用经验与技巧总结 (不断更新中)
- flask报错No module named 'flask.ext'