mysql 常用命令,连接数据库,查看建表语句,批量导入数据,批量更新数据,连接查询
1.
1)MySQL 连接本地数据库,从cmd中进入mysql命令编辑器: root root分别为用户名和密码
mysql -uroot -proot
2)MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)
C:\>mysql -h localhost -u root -p123
2、MySQL 连接远程数据库(192.168.0.201),端口“3306”,用户名为“root”,密码“123”
C:\>mysql -h 192.168.0.201 -P -u root -p123
3.查看mysql建表语句
命令:SHOW CREATE TABLE <table_name>
show create table employees;
| employees | CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` enum('M','F') NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
4.删除mysql 中的表
命令:drop table <表名>
mysql> drop table employees;
Query OK, 0 rows affected (0.15 sec)
5.仅查询employess表中的last_name,first_name和birthd_date三个数据
mysql> select concat(last_name,' ',first_name) as name,birth_date as birthday from employees;
6.
从其他数据库中指定的表中导入数据,employees.employees 导入前10条数据
mysql> insert into employees select * from employees.employees limit 10;
7.批量更新数据
UPDATE `sys_invitation` SET `is_known`='' WHERE (`to_id`='');
8.连接查询
1).原生查询
select *,count(o.order_id) from customers as c ,orders as o where c.customer_id=o.customer_id and c.city='shanghai' group by c.customer_id having count(o.order_id)>0;
2).左连接
select *,count(o.order_id) from customers as c left join orders as o on c.customer_id=o.customer_id where c.city='shanghai' group by c.customer_id having count(o.order_id)>0;
可把left join 改为inner join或者right join.
这里依赖两张表orders和customers.
orders建表语句:
CREATE TABLE `orders` (
`order_id` varchar(10) NOT NULL,
`customer_id` varchar(10) NOT NULL,
PRIMARY KEY (`order_id`)
) ENGINE=InnoDB
插入数据:
mysql> insert into orders select 01332,111;
mysql> insert into orders select 01333,112;
mysql> insert into orders select 01334,113;
mysql> insert into orders select 01335,114;
mysql> insert into orders select 01336,111;
mysql> insert into orders select 01337,112;
mysql> insert into orders select 01338,115;
查看数据:
mysql> select * from orders;
+----------+-------------+
| order_id | customer_id |
+----------+-------------+
| 1332 | 111 |
| 1333 | 112 |
| 1334 | 113 |
| 1335 | 114 |
| 1336 | 111 |
| 1337 | 112 |
| 1338 | 115 |
+----------+-------------+
7 rows in set (0.00 sec)
customers建表语句:
create table customers(customer_id varchar(10) not null, city varchar(10), PRIMARY KEY(customer_id) )ENGINE=INNODB;
customers插入数据:
mysql> insert into customers select 112,'shanghai';
mysql> insert into customers select 113,'shanghai';
mysql> insert into customers values(114,'beijing');
mysql> insert into customers values(115,'beijing');
mysql> insert into customers select 116,'hangzhou';
查看数据:
mysql> select * from customers;
+-------------+----------+
| customer_id | city |
+-------------+----------+
| 111 | shanghai |
| 112 | shanghai |
| 113 | shanghai |
| 114 | beijing |
| 115 | beijing |
| 116 | hangzhou |
+-------------+----------+
6 rows in set (0.00 sec)
9.更改数据库名称
alter table tb1 rename tb2;
将表tb1名称更改为tb2,使用rename命令
10.查看mysql表大小和记录数
SHOW TABLE STATUS FROM 数据库名 LIKE 数据表名;
use testdb;
show table status from testdb like 'xuexi30';
11.
-- 修改表编码
ALTER TABLE `user` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
mysql 常用命令,连接数据库,查看建表语句,批量导入数据,批量更新数据,连接查询的更多相关文章
- mysql命令行查看建表语句
命令如下: SHOW CREATE TABLE tbl_name 例子: mysql> SHOW CREATE TABLE t\G . row ************************* ...
- MySQL查看表结构及查看建表语句
查看表结构:desc 表名 mysql> use recommend; Database changed mysql> desc user; +--------------+------- ...
- hive查看建表语句
查看hive建表语句:show create table tablename; 查看hive表结构:describe tablename; 简写:desc tablename;
- MySQL的字段属性+SQLyog查看建表语句
MySQL的字段属性 写在前面:数据库就是单纯的表,用来存储数据,只有行和列.行代表数据,列代表字段(id.name.age这种就叫字段) 1.长度 2.默认 3.主键 4.非空 5.Unsigned ...
- 【MySQL】查看建表语句
命令如下: SHOW CREATE TABLE tbl_name 例子: mysql> show create table m_zhbess_vehicle_report\G ********* ...
- mysql 查看建表语句
show create table `table_name`; 结果如下:
- 常用的sql标准建表语句
使用指定数据库 use v4base 建一张表 /*************************************************************************** ...
- 通过plsql develop查看建表语句
右键--查看 右下角 如下显示,找出ddl语句 可以看到索引等
- 设置更改root密码、连接mysql、mysql常用命令
6月19日任务 13.1 设置更改root密码13.2 连接mysql13.3 mysql常用命令 13.1 设置更改root密码 使用场景:例如长时间不用忘记了mysql的root密码,那么就需要去 ...
随机推荐
- 超简单!80行代码实现Google日历(拖放、移动、AJAX)
介绍 本实例介绍使用DayPilot Lite for ASP.NET MVC library 类来实现类google日历效果. 在线实例 天视图 星期视图 拖放调整 拖放移动 行代码来实现a ...
- 怎样修改SQL Server 2005/2008的系统存储过程(转)
我们知道,SQL Server 2005/2008的系统存储过程在正常情况下是无法直接修改的. 尽管本文是介绍怎样修改它的,但在这里,我还是建议大家尽量不要去修改它.(好像有点绕哈...) OK,闲话 ...
- 纯css解决div隐藏浏览器原生滚动条,但保留鼠标滚动效果的问题
当我们的内容超出了我们的div,往往会出现滚动条,影响美观.尤其是当我们在做一些导航菜单的时候.滚动条一出现就破坏了UI效果. 我们不希望出现滚动条,也不希望超出去的内容被放逐,就要保留鼠标滚动的效 ...
- C++可变参数列表处理宏va_list、va_start、va_end的使用
VA_LIST是在C语言中解决变参问题的一组宏他有这么几个成员: 1)va_list型变量: #ifdef _M_ALPHA typedef struct{ char* a0; /* ...
- 微信小程序 this.data与this.setData
一.摘要 小程序中我们会经常使用到this.data与this.setData.其中this.data是用来获取页面data对象的,而this.setData是用来更新界面的.那么他们之间的区别与联系 ...
- PHP文件操作[总结]
1.前言 工作中涉及到数据处理,后台需要用到PHP处理数据,之前没有接触过PHP,借此机会了解了一下PHP,PHP很方便,很灵活,编码很舒服,很喜欢用PHP处理后台数据.今天总结一下php文件操作,主 ...
- 自己理解BFC 和 stack context , stack order
1. stack order 发生在BFC计算好了之后. 2.一个一个的BFC里面,不同的block 里面的stack context 会根据 stack order的顺序,进行堆叠.呈现互相遮盖的效 ...
- JqueryValidate表单相同Name不校验问题解决
在使用Jquery validate中遇到一个问题,当表单元素有name相同字段时,validate只校验表单元素name第一个值是否通过校验,比如 <input type="text ...
- nova network工作原理及配置
1. nova network简介 网络管理和配置是云计算中一项非常重要的功能.nova自带的nova-network实现了一些基本的网络模型,允许虚拟机之间的相互通信及虚拟机对internet的访问 ...
- 2014年10月底/终于/HTML5定稿……/技术从来不会成为发展的绝对瓶颈/反而商业成了无法逾越的鸿沟【转载+整理】
原文地址 本文内容 一.HTML5 诞生 二.HTML5 第一阶段: Web 增强与打破垄断 三.HTML5 第二阶段: 移动互联网 四.HTML5 这回真的来了 五.颠覆原生 App 六.还有什么会 ...