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 常用命令,连接数据库,查看建表语句,批量导入数据,批量更新数据,连接查询的更多相关文章

  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. Android -- 获取View宽高

    在activity中可以调用View.getWidth.View.getHeight().View.getMeasuredWidth() .View.getgetMeasuredHeight()来获得 ...

  2. Kaggle 商品销量预测季军方案出炉,应对时间序列问题有何妙招

    https://www.leiphone.com/news/201803/fPnpTdrkvUHf7uAj.html 雷锋网 AI 研习社消息,Kaggle 上 Corporación Favorit ...

  3. 原:wireshare使用技巧收集

    /data/local/tcpdump -p -vv -s 0 -w /sdcard/ThinkDrive.pcap     先抓一个pcap的包. 1. 查看所有的链接与流量 统计->对话 这 ...

  4. Return array from functions in C++

    C++ does not allow to return an entire array as an argument to a function. However, you can return a ...

  5. [Spring Boot] Singleton and Prototype

    When we use Bean to do autowired, it actually use singleton, so even we create multi instanses, they ...

  6. mysql游标的使用 No data - zero rows fetched, selected

    转自:http://blog.sina.com.cn/s/blog_544c72960101bvl3.html 这是一个游标的使用例子. 但是其中有几点需要注意,就是为什么要加入 declare CO ...

  7. python网络爬虫 - 如何伪装逃过反爬虫程序

    有的时候,我们本来写得好好的爬虫代码,之前还运行得Ok, 一下子突然报错了. 报错信息如下: Http 800 Internal internet error 这是因为你的对象网站设置了反爬虫程序,如 ...

  8. 微软BI 之SSAS 系列 - 多维数据集中度量值设计时的聚合函数 (累加性_半累加性和非累加性)

    在 SSAS 系列 - 实现第一个 Cube 以及角色扮演维度,度量值格式化和计算成员的创建 中主要是通过已存在的维度和事实数据创建了一个多维数据集,并同时解释了 Role-Playing Dimen ...

  9. 提示“Resource temporarily unavailable”的原因及解决办法

    问题:Linux环境下编程时,在读串口时,出现"Resource temporarily unavailable"的错误提示. 原因:串口设置成了非阻塞模式,但是没有用select ...

  10. Maven构建应用程序常用配置(转)

    来自:http://shiyanjun.cn/archives/180.html 使用Maven来构建应用程序,可以非常方便地管理应用相关的资源.众所周知,应用程序中涉及到的一些依赖关系,如Java应 ...