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密码,那么就需要去 ...
随机推荐
- kaggle预测
两个预测kaggle比赛 一 .https://www.kaggle.com/c/web-traffic-time-series-forecasting/overview Arthur Suilin• ...
- NLP资源
http://www.cs.columbia.edu/~mcollins/notes-spring2013.html http://web.stanford.edu/class/cs224n/syll ...
- Java-JUC(五):闭锁(CountDownLatch)
闭锁(CountDownLatch) jdk5.0在java.util.concurrent包中提供了CountDownLatch,它是一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一 ...
- (转)HLSL,函数列表
中文列表 函数名 说明 abs 计算输入值的绝对值. acos 返回输入值反余弦值. all 测试非0值. any 测试输入值中的任何非零值. asin 返回输入值的反正弦值. atan 返回输入值的 ...
- ASP入门(十一)-Session小案例
一般来说,在实际开发中,对于 Session 对象使用最多的就是用户登录部分了,这个案例将简单模拟一个用户登录表单.用户是否登录的判断以及用户退出的一系列功能,它一共分了以下几个页面. Login.a ...
- (算法)Travel Information Center
题目: Aps Island has many cities. In the summer, many travellers will come to the island and attend fe ...
- WinRAR如何批量分别压缩不同的文件夹
全选所有文件夹,然后右击添加到压缩文件,然后在文件选项中勾选把每个文件放到单独的压缩文件中 OK了
- android中实现拨号功能
1.要实现拨号功能,首先需要开启拨号权限 修改AndroidManifest.xml文件,添加如下内容: <uses-permission android:name="android. ...
- robot framework-databaselibaray库使用(python)
公司做项目用到了databaselibaray,刚开始使用时碰到了很多问题,网上也查阅了很多资料终于是可以用了,现在整理记录下来,有需要的同学可随意使用: 另,本文主要是databaselibaray ...
- VDP
Today VMware announced a new version on their backup product vSphere Data Protection. They gave it t ...