查看“MYSQL命令”的源代码
←
MYSQL命令
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看并复制此页面的源代码:
==时间段的重叠判断== <source lang="php"> $sql = "SELECT * FROM CTS_ORDER WHERE ACCOUNT_ID = '$account_id' AND STATUS IN (1, 2, 4) " . "AND ( (GET_TIME_EST <= '$start' AND '$start' <= RETURN_TIME_EST) OR (GET_TIME_EST <= '$end' AND '$end' <= RETURN_TIME_EST) OR (GET_TIME_EST > '$start' AND '$end' > RETURN_TIME_EST) )"; </source> ==mysql之union== 今天来写写union的用法及一些需要注意的。 union:联合的意思,即把两次或多次查询结果合并起来。 要求:两次查询的列数必须一致 推荐:列的类型可以不一样,但推荐查询的每一列,想对应的类型以一样 可以来自多张表的数据:多次sql语句取出的列名可以不一致,此时以第一个sql语句的列名为准。 如果不同的语句中取出的行,有完全相同(这里表示的是每个列的值都相同),那么union会将相同的行合并,最终只保留一行。也可以这样理解,union会去掉重复的行。 如果不想去掉重复的行,可以使用union all。 如果子句中有order by,limit,需用括号()包起来。推荐放到所有子句之后,即对最终合并的结果来排序或筛选。 如:(select * from a order by id) union (select * from b order id); 在子句中,order by 需要配合limit使用才有意义。如果不配合limit使用,会被语法分析器优化分析时去除。 ==MYSQL常用命令== 有很多朋友虽然安装好了mysql但却不知如何使用它。在这篇文章中我们就从连接MYSQL、修改密码、增加用户等方面来学习一些MYSQL的常用命令。 一、连接MYSQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1、例1:连接到本机上的MYSQL 首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql> 2、例2:连接到远程主机上的MYSQL 假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命令: mysql -h110.110.110.110 -uroot -pabcd123 (注:u与root可以不用加空格,其它也一样) 3、退出MYSQL命令: exit (回车) 二、修改密码 格式:mysqladmin -u用户名 -p旧密码 password 新密码 1、例1:给root加个密码ab12。首先在DOS下进入目录mysqlbin,然后键入以下命令 <source lang="sql"> mysqladmin -uroot password ab12 </source> 注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。 2、例2:再将root的密码改为djg345 <source lang="sql"> mysqladmin -uroot -pab12 password djg345 </source> MYSQL常用命令(下) 一、操作技巧 1、如果你打命令时,回车后发现忘记加分号,你无须重打一遍命令,只要打个分号回车就可以了。也就是说你可以把一个完整的命令分成几行来打,完后用分号作结束标志就OK。 2、你可以使用光标上下键调出以前的命令。但以前我用过的一个MYSQL旧版本不支持。我现在用的是mysql-3.23.27-beta-win。 二、显示命令 1、显示数据库列表。 show databases; 刚开始时才两个数据库:mysql和test。mysql库很重要它里面有MYSQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。 2、显示库中的数据表: use mysql; //打开库,学过FOXBASE的一定不会陌生吧 show tables; 3、显示数据表的结构: describe 表名; 4、建库: create database 库名; 5、建表: use 库名; create table 表名 (字段设定列表); 6、删库和删表: drop database 库名; drop table 表名; 7、将表中记录清空: delete from 表名; 8、显示表中的记录: select * from 表名; 三、一个建库和建表以及插入数据的实例 drop database if exists school; //如果存在SCHOOL则删除 create database school; //建立库SCHOOL use school; //打开库SCHOOL create table teacher //建立表TEACHER ( id int(3) auto_increment not null primary key, name char(10) not null, address varchar(50) default '深圳', year date ); //建表结束 //以下为插入字段 insert into teacher values('','glchengang','深圳一中','1976-10-10'); insert into teacher values('','jack','深圳一中','1975-12-23'); 注:在建表中(1)将ID设为长度为3的数字字段:int(3)并让它每个记录自动加一:auto_increment并不能为空:not null而且让他成为主字段primary key (2)将NAME设为长度为10的字符字段 (3)将ADDRESS设为长度50的字符字段,而且缺省值为深圳。varchar和char有什么区别呢,只有等以后的文章再说了。 (4)将YEAR设为日期字段。 如果你在mysql提示符键入上面的命令也可以,但不方便调试。你可以将以上命令原样写入一个文本文件中假设为school.sql,然后复制到c:\下,并在DOS状态进入目录\mysql\bin,然后键入以下命令: mysql -uroot -p密码 < c:\school.sql 如果成功,空出一行无任何显示;如有错误,会有提示。(以上命令已经调试,你只要将//的注释去掉即可使用)。 四、将文本数据转到数据库中 1、文本数据应符合的格式:字段数据之间用tab键隔开,null值用\n来代替. 例: 3 rose 深圳二中 1976-10-10 4 mike 深圳一中 1975-12-23 2、数据传入命令 load data local infile "文件名" into table 表名; 注意:你最好将文件复制到\mysql\bin目录下,并且要先用use命令打表所在的库 。 五、备份数据库:(命令在DOS的\mysql\bin目录下执行) mysqldump --opt school>school.bbb 注释:将数据库school备份到school.bbb文件,school.bbb是一个文本文件,文件名任取,打开看看你会有新发现。 ==MySQL操作== <source lang="bash"> #两张表的全联合 ( SELECT 'a' AS TYPE , id, name, `desc` FROM articles WHERE name LIKE '%m%' ) UNION ALL ( SELECT 'p' AS TYPE , id, name, `desc` FROM products WHERE name LIKE '%m%' ) SELECT COUNT(*) as total FROM ( ( SELECT 'article' AS type , id, name, `desc` FROM articles WHERE type_id IN (42,43,44) AND name LIKE '%电子展%' ) UNION ALL ( SELECT 'product' AS type , id, name, `desc` FROM products WHERE name LIKE '%电子展%' ) ) T #导出 C:\wamp\bin\mysql\mysql5.5.20\bin>mysqldump -u root -p mvp > mvp.sql </source> <source lang="sql"> select id from goods group by keyid having count(*)>1 SELECT SUM( IF( score =10, 1, 0 ) ) FROM fanwe_referrals WHERE rid =72; UPDATE zyy_posts_charts SET thumb_url = REPLACE ( thumb_url, '114.113.148.26', 'cms.zyyic.com' ); update elong_hotel elong, think_hotel think set think.businessZone=elong.businessZone where elong.hotelId=think.elong_hotel_id create table cs_bak1 as (select * from cs); select * from rapee_order where user_email="sky007_tom@163.com" order by add_time DESC; alter table goods add brand varchar(50); ALTER TABLE admin_user RENAME TO a_user; MySQL显示乱码,可用set names ‘gbk’; Show columns from sdb_products; Where name IS NULL——所有name字段为空的记录 Alter table goods engine=innodb; Show variables like ‘table_type’; Show ENGINES\G; update goods set class=”Collection” where id=4; Create database new_rapee; use new_rapee; alter table goods modify filling varchar(240); insert into goods (name,brand) values (”check”,”Bursa”); delete from goods_category where id=14; create table test1(serial int unsigned not null primary key auto_increment,id varchar(20) not null,passwd varchar(20)); alter table goods_category add id int not null auto_increment primary key; alter table cart drop id; show tables; alter table specification change specification_category_id category_id int; select a.category_id,b.goods_category,b.sub_category_name from specification a join goods_category b on(a.category_id=b.id and a.goods_computer_code='Rab-296'); select p.company_id,p.name,s.* from products p join (select product_id , sum(qty) , min(price) , max(price) from product_stock group by product_id ) s on(p.rec_id=s.product_id and p.company_id=23) ORDER BY rec_id DESC select s.type,s.label,s.org_id,p.product_id from shop_shipment s left join (select * from shop_product_shipment ) p on(s.type='配送点自取' and p.product_id=93 and p.label=s.label) select * from (select s.type, s.label, s.org_id, p.product_id from shop_shipment s left join (select * from shop_product_shipment ) p on(p.product_id=93 and p.label=s.label)) o where o.org_id=26 select a.member_id,m.bm_name,p.bm_profile_address from biz_app_access a join biz_member m join biz_member_profile p on(m.bm_on_org=26 and a.member_id=p.bm_profile_bm_id and a.member_id=m.bm_id and a.app_action='商品发放') </source> ==PostgreSQL操作== <source lang="sql"> // 把product表的main_id,更新到details表里。 update t_product_details detail set product_id = product.main_id from t_product product where detail.product_code = product.product_code </source> ==PostgreSQL操作:清除未删除干净的记录== <source lang="sql"> delete from t_product_details where product_id in (select A.product_id from t_product_details as A where A.product_id not in (select main_id from t_product) ORDER BY product_id) delete from t_product_details_writing where product_id in (select A.product_id from t_product_details_writing as A where A.product_id not in (select main_id from t_product) ORDER BY product_id) delete from t_product_important_info where product_id in (select A.product_id from t_product_important_info as A where A.product_id not in (select main_id from t_product) ORDER BY product_id) </source> 参考: SQL mysql 查询存在A表而不在B表中的 记录 https://blog.csdn.net/qq_42483473/article/details/107985131
返回
MYSQL命令
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息