zoukankan      html  css  js  c++  java
  • 解决远程链接mysql

    sqlyog下载:https://www.onlinedown.net/soft/24926.htm

    注册码:ttrar
    序 列 号(Code):ec38d297-0543-4679-b098-4baadf91f983

    修改密码:

    UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
    FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误

    如果遇到操作过程中myql数据丢失,请进行如下操作:

    1.关闭mysql
       # service mysqld stop
    2.屏蔽权限
       # mysqld_safe --skip-grant-table
       屏幕出现: Starting demo from .....
    3.新开起一个终端输入
       # mysql -u root mysql

    解决远程链接额1130报错

    mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'
    IDENTIFIED BY '123456' WITH GRANT OPTION;
    mysql>FLUSH PRIVILEGES;

    开放端口号:/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

    sql建表语句

    数据库:查看 创建 删除
    数据:增删改查
    存储过程:批量创建数据
    DDL语句:create,alter,drop建表删除数据
    DML语句:update,insert,delete,select对数据操作得增删改查
    DCL语句:是数据库控制功能

    show databases查看数据库
    show create database wjx;查看创建数据库语句
    create databases wjx charset utf8'创建数据库并且不会有乱码
    drop databases wjx 删除数据库
    use wjx 选择数据库

    表得操作
    show tables 查看表
    int(整型) float(浮点型)
    char(字符串:定长)
    vachar(字符串类型:变长)
    text(文本类型)

    表:增删改查
    建表
    自增长:auto_incremant,自动加1
    不为空:not null
    默认值:default ‘xx’
    唯一的:unique
    指定字符集:charset
    BIGINT 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。存储大小为 8 个字节。
    主键:主键就是可以唯一可以代表这个数据的,不能重复的
    primary key 主键具有唯一性 不能为空
    外键:就是用来表示两个表之间的关系
    create table score(
    id int auto_increment primary key,
    s_id int not null,
    grade float not null
    );
    wjx里面的主键就是score里面的外键,让两个表有关联关系
    create table jxz(
    id int auto_increment primary key,
    name varchar(10) not null,
    sex varchar(3) default '男',
    addr varchar(50),
    phone int not null unique
    );
    删除
    drop table 表名
    修改
    alter table 旧表名 rename 新表名
    修改数据类型
    alter table 表名 modify 字段名 #修改字段的数据类型
    alter table change 旧名 新名 字段
    modify和change的区别就是change的指定一个新的字段名
    增加字段
    alter table 表名 add money float;
    增加字段在id后面
    alter table 表明 add money after id
    删除字段
    alter table 表名 drop addr
    查询
    desc 表名 查看表结构
    show create table 表名 查看建表语句

    数据操作:
    增加
    有两种:
    前面写几个字段,后面插入就有几个值
    insert into 表名 (表内字段) values(数据信息)
    不指定字段,写全部的字段值
    insert into 表名 values(数据信息)
    同时插入多条可以写多个字段,中间用逗号隔开
    truncate 表名 删除数据

    修改数据
    update 表名 set money where 条件=xxx
    如果不指定条件的话,修改的是整个表的数据
    修改多个字段
    update 表名 set money,phone where 条件=xxx
    中间加个逗号,加条件
    在原来的值基础上做修改
    update jxz set money=money+100

    删除数据
    delete from blk;删除所有数据
    delete删除自增长id还会增长
    truncate清空的表,自增长从1开始,truncate比delete要快,
    因为truncate是从磁盘上直接删除,数据恢复不了
    set @autocommit=0; select @autocommit 关闭自动提交
    mysql默认是自动提交的
    rollbackl;可以查出数据
    删除指定数据
    delete from blk where username = 'wjx'
    linux命令
    ls * temp 查看所有以temp结尾的
    ls *niu* 查看中间所有包含niu的
    查询语句select
    查询字段值,指定查询字段
    select name,sex,money,phone from jxz;
    查看所有字段
    select * from jxz;
    指定查询字段
    select * from blk where sex='男';
    查询多个指定条件,多个条件必须同时满足
    select * from blk where sex='男' and money>100;
    有一个条件即可,或的关系,用or
    select * from blk where sex='男' or money>100;
    查询性别不等于男的,<>也是不等于
    select * from blk where sex!='男'
    select * from blk where sex<>'男'
    模糊匹配,用like不能用=,%号就是包含的意思,通配符用法
    %号在最后,查看开头,两边都是%是包含的意思,百分号在开头,以什么结尾
    select * from jxz where addr like '东京%';
    下划线通配符表示匹配任意单字符
    select * from jxz where name like '姚_'

    起别名就是在表名后面加空格a,然后在用a.xxx,空格后面加as也可以省略
    select a.name from jxz a where a.name='wjx';
    给列起别名
    select a.name 学生名称 from jxz a where a.name='wjx';

    查找多个学生的成绩,直接用in
    select * from jxz where name in('wjx','chuzhang') and money>100;

    查找工资5000到10000之间的数据,用between and必须是数据,中文不能用
    select * from jxz where money between 5000 and 10000;

    排序,asc默认是升序,根据那个字段默认进行排序
    select * from jxz orderby money asc;
    desc是降序
    select * from jxz orderby money desc;

    查询空值,一种是空字符串,一种是为null,为null的就用is null
    select * from jxz where name='' or name is null;
    查询不是空的,is not null
    select * from jxz where name='' or name is not null;
    select * from jxz where name!='';

    剔重和限制条数,distinct就是去重
    select distinct addr from jxz ;

    聚合函数
    select count(*) from jxz;查看多少条
    求最大最小值
    select max(money) from jxz;查看最大值
    select min(money) from jxz;查看最小值
    select avg(money) from jxz;查看平均值
    select sum(money) from jxz;查看总数

    分组group by
    按照性别进行分组
    select * from blk group by sex;
    显示每个组有多少人
    select * ,count(*) from blk group by sex;
    根据性别及进行分组,在查看每个组有多少人
    select sex,count(*) from blk group by sex;
    分组之后查找多个条件就不能用where,需要用having
    select * from blk group by sex having like name '%w';
    如果group by 后面有条件的话就必须用having子句,having子句里面用到的字段
    必须出现在select后面,如果order by和group by一起用的话
    order by 必须写在group by 后面

    根据多个字段进行分组,根据性别和班级进行分组
    select *,count(*) from blk group by sex,class

    多表查询
    查询两个表里面username是wjx的信息,并附带别名
    这两个表都有一个id相关联,把这个id一关联两张表就有关系了
    select a.username b.money from user a,money b where a.id=b.userid and a.username='wjx';
    4.18建表语句
    订单表
    create table 表名(
    id int primary key auto_increment,
    user_id int,
    price float
    );
    备注:不能创建名字order名字的表
    也就是不能用关键字作为表名
    两个表里面都存在的数据查出来
    select a.username,b.money,c.userid from user a,money b, price c where a.id=b.id and a.username='wjx' and a.id=c.id;

     左连接
    以左边的表为准 left join 用on进行链接,把左边所有的数据都查出来
    select * from jxz a left join score b on a.id=b.s_id;

    右连接
    以右边的表为准 right join 用on进行链接,把右边所有的数据都查出来
    select * from jxz a right join score b on a.id=b.s_id;

    内链接
    inner,两边都匹配的才能查出来
    select * from jxz a inner join score b on a.id=b.s_id;

    子查询
    select * from jxz where username='wjx';
    select * from score where id =7
    总结为一条sql,把一条sal的结果作为另一条sql的条件就是子查询
    select * from score a where a.s_id=(select id from jxz where name='wjx');

    把子查询当成一个表 4.58
    练习题
    查出姓名为wjs的学生名称,钱和成绩
    select a.name,a.money,b.grade from jxz a,score b where a.id=b.s_id and a.name='wjx';
    用子查询
    select
    select a.name,a.money,b.grade from jxz a, (select s_id,grade, from score) b,
    where a.id=b.s_id and a.name='wjx'

    limit
    limit几就是查出几行
    select * from jxz limit3;查出3行
    查出1-5,不包括第一行
    select * from jxz limit 1,5

    union是连接两条sql语句之间的,查询字段的数量是一样的
    字段类型必须一样
    select id,name from union select id,t_name from teacher

    union all 和union的区别
    union是去重,union all不会去重,union all的效率比较高

    面试题
    考勤表,上午打卡时间,下午打卡时间,要求上午9点打卡,下午6点打卡
    查出所有打卡异常的员工
    1.上午为空
    2.下午为空
    3.上下午都为空
    4.迟到,上去晚于9点
    5.早退,下午早于6点
    select * from kq a where a.am is null ,
    union select * from kq a where a.pm is null,
    union select * from kq a where a.am is null and a.pm is null,
    union select ka a where a.am > '9:00',
    union select ka a where a.pm < '6:00',

    dcl语句
    user表中的host就是允许那个用户进行登陆的
    把加密后的密码和数据库当中进行对比
    update user set passwd=password('123456') where user='root';

    数据库权限:
    flush privileges刷新权限

    grant all on所有的权限
    *.* to 'andashu'@'localhost'数据库下面所有的表
    identified by '123456'密码
    with grant option有执行grant语句权限

    grant all on所有的权限
    *.* to 'andashu'@'%'数据库下面所有的表
    identified by '123456'密码
    with grant option有执行grant语句权限

    存储过程
    批量造数据
    delimiter $$; 把分号改成$$的时候遇到分号就不结束了
    create procedure big_data(num int)代表要造多少条数据,big_data是名称
    begin是开始得意思
    declare i int;定义一个计数器
    set i=0;定义一个初始值
    while i<num do 只要i小于1000,那就一直执行这一句话
    insert into jxz (stu_name,money) values(count('wjx',i),20000)#count是连接不同类型的数据
    把字符串和数字拼接到一起
    set i=i+1 重新赋值
    sql语句块
    end
    $$;
    delimiter ;

    call big_data(50)#调用

    备份数据库,恢复数据
    mysqldump -root -p123456 blk>blk.sql备份数据库
    mysqldump -root -p123456 -A>all.sql备份所有数据库,所有的表

    回复数据库
    mysql -uroot -p123456 blk<blk.sql

    CREATE table user (
    id int PRIMARY key AUTO_INCREMENT,
    username varchar(20) not null UNIQUE,#unique是不能重复
    passwd VARCHAR(32) not null,
    money FLOAT DEFAULT 10000#default是默认值的意思
    );

    windows启动redis
    resdis-server.exe redis.windows.conf
    redis-cli.exe





  • 相关阅读:
    数论 UVA 10943
    数论 UVA 11889
    数论 UVA 11388
    UVA 572
    hdu 1016
    poj 1308
    poj 1363
    java web-----servelet
    java IO文件读写例子(OutputStream,InputStream,Writer,Reader)
    java web环境配置类型问题
  • 原文地址:https://www.cnblogs.com/wangjunxi/p/7898327.html
Copyright © 2011-2022 走看看