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)
MySql 创建/删除数据库的更多相关文章
- mysql 创建++删除 数据库
创建RUNOOB数据库,并设定编码集为utf8 CREATE DATABASE IF NOT EXISTS RUNOOB DEFAULT CHARSET utf8 COLLATE utf8_gener ...
- MySQL 创建删除和选择数据库
使用 create 命令创建数据库,语法如下: CREATE DATABASE 数据库名; 删除数据库 drop database <数据库名>; 选择数据库 use 数据库名 Datab ...
- php 创建删除数据库
<?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, ...
- mysql创建/删除表的例子
创建表 简单的方式 CREATE TABLE person ( number INT(11), name VARCHAR(255), birthday DATE ); 或者是 CREATE TABLE ...
- mysql创建的数据库在电脑什么位置?
你可以在mysql 命令行里执行 show variables like '%datadir%'; 显示出你数据文件的路径,能找到以你创建的数据库的名字的文件夹了.
- mongodb的创建删除数据库
1.创建数据库 use 命令 MongoDB use DATABASE_NAME 用于创建数据库.该命令将创建一个新的数据库,如果它不存在,否则将返回现有的数据库. 语法: use DATABASE ...
- MongoDB自学------(2)创建删除数据库及集合
一.创建数据库 二.查看所有数据库 三.删除数据库 四.创建集合 五.删除集合 六.集合用法介绍 1.创建集合 2.删除集合 下一篇链接:https://www.cnblogs.com/LinHuCh ...
- mysql 如何删除数据库中所有的表
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')FROM information_schema.tablesWHERE table_sch ...
- PHP MySQL Delete删除数据库中的数据
PHP MySQL Delete DELETE 语句用于从数据库表中删除行. 删除数据库中的数据 DELETE FROM 语句用于从数据库表中删除记录. 语法 DELETE FROM table_na ...
随机推荐
- SharePoint服务器端对象模型 之 访问文件和文件夹(Part 4)
(四)列表附件 列表的附件也是文件系统的一部分,它依附于普通列表的列表条目之上(文档库没有附件),它的操作在一些地方和文档库中文档的操作非常类似. 1.附件的读取 一个列表条目的附件可以使用SPL ...
- 20160924-2——mysql常见问题集锦
一.数据类型相关问题 1.varchar(N)占用多少空间 (1)varchar(N)里的N是字符数,而不是字节数: (2)字符类型(varchar text blob等)空间=字符实际长度+字段长度 ...
- Storm 提交任务过程详解 (不对地方麻烦指正)
1.使用的是Storm中自带的一个测试jar包 提交下这任务到storm中去 storm jar /usr/local/app/storm/examples/storm-starter/storm-s ...
- CAS单点登录------未认证授权服务
问题背景:之前我使用的127.0.0.1进行CAS 直接url 进行过滤! 后来我用nginx 进行反向代理 出现问题: 如下图 第一眼,就在内心想,草这什么鬼! 麻蛋! ON! 调试了五分 ...
- 新手之使用git
本篇博客针对不会Git的小童鞋,大神们可以绕过,错误之处谢谢指正: 关于GitHub的强大此处不在说明,知道GitHub也有一段时间了,但是一直苦于不会使用. 本篇文章介绍的是如何将工程代码托管到上面 ...
- 检测当前的语言环境是否使用了 UTF-8 编码(三篇文章:先用setlocale()设置编码,再用nl_langinfo()进行检测。locale对象可以使用langLocale.name() == "zh_CN"判断)
C/C++程序中,locale(即系统区域设置,即国家或地区设置)将决定程序所使用的当前语言编码.日期格式.数字格式及其它与区域有关的设置,locale设置的正确与否将影响到程序中字符串处理(wcha ...
- Python3.6全栈开发实例[003]
3.检查传入列表的长度,如果大于2,将列表的前两项内容返回给调用者. li = [11,22,33,44,55,66,77,88,99,000,111,222] def func3(lst): if ...
- linux安装jdk_1.8
转载自http://blog.csdn.net/ldl22847/article/details/7605650 1.下载jdk的rpm安装包,这里以jdk-8u141-linux-x64.rpm为例 ...
- windows 和rhel,centos双系统安装
1:首先确保你先安装为windows系统,为indows7以上的把. 2:安装好为indows系统后,进入系统后把磁盘分区,分出足够的空间为安装linux. 3:再为windows下使用软碟通等工具制 ...
- 【转】Python爬虫(5)_性能相关
爬虫性能相关 一 背景知识 爬虫的本质就是一个socket客户端与服务端的通信过程,如果我们有多个url待爬取,采用串行的方式执行,只能等待爬取一个结束后才能继续下一个,效率会非常低. 需要强调的是: ...