1.

1)MySQL 连接本地数据库,从cmd中进入mysql命令编辑器: root root分别为用户名和密码

  1. mysql -uroot -proot

2)MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格)

  1. C:\>mysql -h localhost -u root -p123

2、MySQL 连接远程数据库(192.168.0.201),端口“3306”,用户名为“root”,密码“123”

  1. C:\>mysql -h 192.168.0.201 -P -u root -p123

3.查看mysql建表语句

  1. 命令:SHOW CREATE TABLE <table_name>
  2.  
  3.  show create table employees;
  4.  
  5. | 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 中的表

  1. 命令:drop table <表名>
  1. mysql> drop table employees;
  2. Query OK, 0 rows affected (0.15 sec)

5.仅查询employess表中的last_name,first_name和birthd_date三个数据

  1. mysql> select concat(last_name,' ',first_name) as name,birth_date as birthday from employees;

6.

从其他数据库中指定的表中导入数据,employees.employees 导入前10条数据

  1. mysql> insert into employees select * from employees.employees limit 10;

7.批量更新数据

  1. UPDATE `sys_invitation` SET `is_known`='' WHERE (`to_id`='');

8.连接查询

1).原生查询

  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).左连接

  1. 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建表语句:

  1. CREATE TABLE `orders` (
  2. `order_id` varchar(10) NOT NULL,
  3. `customer_id` varchar(10) NOT NULL,
  4. PRIMARY KEY (`order_id`)
  5. ) ENGINE=InnoDB

插入数据:

  1. mysql> insert into orders select 01332,111;
  2. mysql> insert into orders select 01333,112;
  3. mysql> insert into orders select 01334,113;
  4. mysql> insert into orders select 01335,114;
  5. mysql> insert into orders select 01336,111;
  6. mysql> insert into orders select 01337,112;
  7. mysql> insert into orders select 01338,115;

查看数据:

  1. mysql> select * from orders;
  2. +----------+-------------+
  3. | order_id | customer_id |
  4. +----------+-------------+
  5. | 1332 | 111 |
  6. | 1333 | 112 |
  7. | 1334 | 113 |
  8. | 1335 | 114 |
  9. | 1336 | 111 |
  10. | 1337 | 112 |
  11. | 1338 | 115 |
  12. +----------+-------------+
  13. 7 rows in set (0.00 sec)

customers建表语句:

  1. create table customers(customer_id varchar(10) not null, city varchar(10), PRIMARY KEY(customer_id) )ENGINE=INNODB;

customers插入数据:

  1. mysql> insert into customers select 112,'shanghai';
  2. mysql> insert into customers select 113,'shanghai';
  3. mysql> insert into customers values(114,'beijing');
  4. mysql> insert into customers values(115,'beijing');
  5. mysql> insert into customers select 116,'hangzhou';

查看数据:

  1. mysql> select * from customers;
  2. +-------------+----------+
  3. | customer_id | city |
  4. +-------------+----------+
  5. | 111 | shanghai |
  6. | 112 | shanghai |
  7. | 113 | shanghai |
  8. | 114 | beijing |
  9. | 115 | beijing |
  10. | 116 | hangzhou |
  11. +-------------+----------+
  12. 6 rows in set (0.00 sec)

 9.更改数据库名称

  1. alter table tb1 rename tb2;

将表tb1名称更改为tb2,使用rename命令

 10.查看mysql表大小和记录数

  1. SHOW TABLE STATUS FROM 数据库名 LIKE 数据表名;
  2. use testdb;
  3. show table status from testdb like 'xuexi30';

11.

-- 修改表编码

  1. ALTER TABLE `user` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

mysql 常用命令,连接数据库,查看建表语句,批量导入数据,批量更新数据,连接查询的更多相关文章

  1. mysql命令行查看建表语句

    命令如下: SHOW CREATE TABLE tbl_name 例子: mysql> SHOW CREATE TABLE t\G . row ************************* ...

  2. MySQL查看表结构及查看建表语句

    查看表结构:desc 表名 mysql> use recommend; Database changed mysql> desc user; +--------------+------- ...

  3. hive查看建表语句

    查看hive建表语句:show create table tablename; 查看hive表结构:describe  tablename; 简写:desc tablename;

  4. MySQL的字段属性+SQLyog查看建表语句

    MySQL的字段属性 写在前面:数据库就是单纯的表,用来存储数据,只有行和列.行代表数据,列代表字段(id.name.age这种就叫字段) 1.长度 2.默认 3.主键 4.非空 5.Unsigned ...

  5. 【MySQL】查看建表语句

    命令如下: SHOW CREATE TABLE tbl_name 例子: mysql> show create table m_zhbess_vehicle_report\G ********* ...

  6. mysql 查看建表语句

    show create table `table_name`; 结果如下:

  7. 常用的sql标准建表语句

    使用指定数据库 use v4base 建一张表 /*************************************************************************** ...

  8. 通过plsql develop查看建表语句

    右键--查看 右下角 如下显示,找出ddl语句 可以看到索引等

  9. 设置更改root密码、连接mysql、mysql常用命令

    6月19日任务 13.1 设置更改root密码13.2 连接mysql13.3 mysql常用命令 13.1 设置更改root密码 使用场景:例如长时间不用忘记了mysql的root密码,那么就需要去 ...

随机推荐

  1. Backbone.js 使用 Collection

    在前面我们的 Backbone.js 用上了 Model, 但绝大数的情况下我们处理的都是一批的 Model 数据列表,所以需要有一个 Collection 来容纳 Model, 就像 Java 里最 ...

  2. js 处理URL实用技巧

    escape().encodeURI().encodeURIComponent()三种方法都能对一些影响URL完整性的特殊字符进行过滤.     但后两者是将字符串转换为UTF-8的方式来传输,解决了 ...

  3. SQL操作查漏补缺

    SQL教程地址:http://www.w3school.com.cn/sql/index.asp TOP 子句 TOP 子句用于规定要返回的记录的数目. 对于拥有数千条记录的大型表来说,TOP 子句是 ...

  4. TNTSearch 轻量级全文索引 + 中文分词

    TNTSearch 轻量级全文索引+中文分词 选用 TNTSearch 的原因:轻,方便移植,不需要额外安装服务,能减少后期维护的工作量.搜索的效果也还不错,可以满足大多数项目场景,如果对性能和精准度 ...

  5. wifidog 源码初分析(4)-转

    在上一篇<wifidog 源码处分析(3)>的流程结束后,接入设备的浏览器重定向至 路由器 上 wifidog 的 http 服务(端口 2060) /wifidog/auth 上(且携带 ...

  6. linux命令大全网站

    一. linux命令大全网站 http://man.linuxde.net/watch

  7. Mybatis源码分析之SqlSession和Excutor(二)

    通过上一篇文章的分析我们,我初步了解了它是如何创建sessionFactory的(地址:Mybatis源码分析之SqlSessionFactory(一)), 今天我们分析下Mybatis如何创建Sql ...

  8. Provide your license server administrator with the following information.error code =-42,147

    ArcEngine应用程序开发中,许可不必不可少的.一般采取两种方式来获取许可——License控件和AoInitialize类,但今天在VS2010打开程序时,隔一会弹出错误窗口:Provide y ...

  9. 微信小程序开发-滑动操作

    在实际应用中,当某种手势被触发后,在用户没有放开鼠标或手指前,会一直识别为该手势.比如当用户触发左滑手势后,这时再向下滑动,仍要按照左滑手势来处理. 可以定义一个标记来记录第一次识别到的手势,如果已识 ...

  10. 关于testNG和JUnit的对比

    关于选择JUnit还是选testNG,这几篇文章,建议读一读: API参考文档: Junit API文档:http://junit.org/junit4/javadoc/latest/index.ht ...