zoukankan      html  css  js  c++  java
  • mysql账号权限管理(一)

    1.mysql默认安装是没有密码,默认账号是root账号管理员
    默认情况没有密码,数据库服务器都不允许远程操控
    查找当前mysql的账号
    select user,password,host from mysql.user;
    删除账号
    delete from mysql.`user` where user ='';
    delete from mysql.`user` where host='192.168.2.2';
    drop user yy;
    远程管理


    E:mysqlin>mysql -h192.168.2.3 -uroot -p
    Enter password: ***

    给服务器增加账号密码
    修当前登录账号的密码
    update mysql.user set password=password('123'),host='%'
    update mysql.user set password=passwored('123')hoset='192.168.2.3';
    修改密码
    update mysql.`user` set password ='';
    修改当前登录账号的密码
    set password=password('abc');
    取消test账号的密码
    set password for test@localhost =''
    修改账号test密码为abc
    set password for tset @localhost =password('abc')
    %表示任意一台电脑都可以用
    必须要刷新才可以
    刷新所有账号的信息
     flush privileges;
    建立账号,并指定密码为aa 普通账号,只有登录服务器的能力
    create user 'admin' @'localhost' identified by 'aa';
    建立账号
    create user admin identified by '123';
    建立没有密码的任何主机使用的账号bc,除了登陆没有任何权利
    create user bc;
    建立db数据库的指定管理员账号为eee,密码没有,任意主机
    grant all on db.* to eee;
    建立db数据库中的vv表指定管理员账号,没有密码任意主机
    grant all on db.vv to sss;
    建立超级管理员账号没有密码任意主机账号yyy
    grant all privileges on *.* to yyy;
    grant all on *.* to yy;
    建立没有密码的 任何主机使用的账号
    create user abc;
    grant 授权
    grant select on xx.`student` to bc;
    revoke 收回  取消 权限   
    revoke select on xx.`student` from bc;
    修改当前登录账号的密码
    set password=password('abc');

    create user yy;
    rename user yy to abc;
    set password for abc=password('aa');
    set password for 'abc'@'%'=password('aa');

    数据库的备份恢复
    数据库的导出,命名写上日期
    mysqldump -hlocalhost -uroot -pabc db>f:/db201554.sql




    导出2个数据库

    删除数据库

    先建库再恢复数据

    恢复导入数据
    mysqlin>mysql -hlocalhost -uroot -pabc db<f:/db20150504-student.sql

    mysql>source f:/ff.sql  执行ff.sql文件
    数据转接快速录入
    建立文件f:/st.txt
    100,张三,80
    100,张三,100
    先建立表

    repair 修复 optimize 优化
    一般mysql无法访问时可以使用修复来修复被破坏的表
    repair table student,teacher 修复表
    优化时减少磁盘占用空间
    optimize tble studnet,teacher 优化   删除了不会立即释放空间,当执行优化的时候才可以释放空间
    数据库(含数据)的导出xx数据库中所有表对象  在-p 后面加入-q还会增加导入导出的速度导出是> 导入时<
    E:mysqlin>mysqldump  -hlocalhost -uroot -p xx>f:/xx20150504.sql
    加q
    E:mysqlin>mysqldump -hlocalhost -uroot -p -q xx book >f:/book2015.sql
    数据库(无数据)的导出只有表结构
    E:mysqlin>mysqldump -uroot -p -d xx>f:/201501.sql
    只导出xx数据库中book表的结构及内容
    E:mysqlin>mysqldump -hlocalhost -uroot -p xx book>f:/book2015.sql
    导入book表信息
    E:mysqlin>mysql -hlocalhost -uroot -p xx<f:/book2015.sql
    导入加-q
    E:mysqlin>mysql -hlocalhost -uroot -p -q xx <f:/book2015.sql
    数据库的导入
    E:mysqlin>mysql -hlocalhost -uroot -p xx<f:/xx20150504.sql

    如果库也被删掉应该先建库之后再导入数据
    mysql> create database xx default character set utf8;
    E:mysqlin>mysql -hlocalhost -uroot -p -q xx<f:/xx2.sql
    执行xx2.sql里面的所有语句
    mysql> source f:/xx2.sql
    -- 修改账号名
    rename user 'yyy' to 'aa';
    -- 修改账号名及服务器ip地址
    rename user 'fafsa'@'192.168.1.2' to 'aaa'@'192.168.2.2';

    建立文件i:/st.txt
    1000,张三,80
    1001,李四,30
    先建立表 st
    mysql> create table st(sid int,sname varchar(30),
    sscore tinyint,primary key(sid));
    -- 数据导入 
    load data infile 'f:/st.txt' into table st fields terminated by '\,' lines terminated by ' ';

    load data infile ':/student.txt' into table student fields terminated by '\,' lines terminated by ' ';

    -- 查询出来的数据导出 指定文件上   
    select sid,sname,sscore 
    into outfile 'i:/sbak.txt' 
    fields terminated by '\,' 
    lines terminated by ' ' 
    from student where sscore<60;









  • 相关阅读:
    Centos下一个server安装的版本号mysql
    android 玩愤怒的小鸟等游戏的时候全屏TP失败
    6.8 一般处理语言
    [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem
    POJ1185:火炮(减少国家)
    教你如何下载音乐的网站只试镜
    实现js呼叫流行
    [Angular 2] Async Http
    [Typescript] Function defination
    [React] React Router: setRouteWillLeaveHook
  • 原文地址:https://www.cnblogs.com/lsr111/p/4480450.html
Copyright © 2011-2022 走看看