Mysql数据库。。

来源:互联网 发布:淘宝手机端详情页像素 编辑:程序博客网 时间:2024/04/25 21:58

登录:mysql –h ip地址 –P 端口号 –u 用户名 –p 密码

 

常用sql:

1.    insert into表名(列名…) values(?,?...);

2.    update表名set列名=? where列名=?;

3.    delete from表名where …;

4.    select * from表名;

 

关键字:

1.    distinct 唯一的输出记录。

select distinct 列名 from 表名;

2.    Order by 列名;(desc 降序,asc 升序)

3.    BINARY 强制区分大小写 order by binary 列名;

 

授权法:

Grant all privileges on *.* to ‘root’@’ip或者%’ identified by ‘密码’ with grant option;

Flush rivileges;

 

往表中插入不重复数据:

正确的解决方法是:
首先,在创建表时,将不需要重复的字段设置为unique,然后在插入时,使用insert ignore语句。

例如:(数据库用的是mysql5
创建一张表用来存储用户:
create table user_info
(
   uid mediumint(10) unsigned NOT NULL auto_increment primary key,
   last_name char(20) not null,
   first_name char(20) not null,
   unique ( last_name, first_name)
);

插入数据:
insert  ignore  into  user_info (last_name,first_name)  values ('x','y');
//
这样一来,如果表中已经存在last_name='x'first_name='y'的数据,就不会插入,如果没有就会插入一条新数据。