zoukankan      html  css  js  c++  java
  • MySQL学习

    MySQL加密码
    mysqladmin -uroot password "123456"

    创建用户
    insert into user (host,user,password) values('%','lubing','123456');  

    创建数据库
    create database phplampDB;
    删除数据库
    drop database phplampDB;


    mysql数据库忘记密码
    vi /etc/my.cnf加入一下语句
    skip-grant-tables
    然后进入MySQL数据库修改MySQL密码
    >use mysql
    >update user set password=password("123456") where user="root";
    重启MySQL数据库
    service  mysqld restart


    授权访问
    grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
    制定部分权限予以授权
    grant select,update on phplampDB.* to phplamp@localhost identified by '1234';

    主从同步授权
    GRANT REPLICATION SLAVE ON *.* TO test@10.99.199.4 IDENTIFIED BY'123456';
    flush privileges;
    主库/etc/my.cnf
    [mysqld]
    log-bin=mysql-bin
    server-id =1
    binlog-do-db=lubing


    从库/etc/my.cnf
    [mysqld]
    server-id        = 2
    master-host        = 10.99.199.2
    master-user        = test
    master-password        = 123456
    master-port        = 3306
    master-connect-retry    = 5
    replicate-do-db        = lubing
    replicate-ignore-db    = mysql

    CHANGE MASTER TO MASTER_HOST='10.99.199.2',

    MASTER_USER='test',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-

    bin.000001',MASTER_LOG_POS=106;


    1、显示数据库

     show databases;

    2、选择数据库

    use 数据库名;

    3、显示数据库中的表

    show tables;

    4、显示数据表的结构 

    describe 表名;

     5、显示表中记录 

    SELECT * FROM 表名

     6、建库

     create databse 库名;

     7、建表

    复制代码
    create table 表名 (字段设定列表);
    
    mysql> create table name(
        -> id int auto_increment not null primary key ,
        -> uname char(8),
        -> gender char(2),
        -> birthday date );
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> show tables;
    +------------------+
    | Tables_in_userdb |
    +------------------+
    | name             |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> describe name;
    +----------+---------+------+-----+---------+----------------+
    | Field    | Type    | Null | Key | Default | Extra          |
    +----------+---------+------+-----+---------+----------------+
    | id       | int(11) | NO   | PRI | NULL    | auto_increment |
    | uname    | char(8) | YES  |     | NULL    |                |
    | gender   | char(2) | YES  |     | NULL    |                |
    | birthday | date    | YES  |     | NULL    |                |
    +----------+---------+------+-----+---------+----------------+
    4 rows in set (0.00 sec)
    
    注: auto_increment 自增
         primary key    主键
    复制代码

     8、增加记录

     insert into name(uname,gender,birthday) values('张三','','1971-10-01');

     9、修改记录

    update name set birthday='1971-01-10' where uname='张三';

     10、删除记录

    delete from name where uname='张三';

     11、删除表

    drop table 表名

     12、删除库

     drop database 库名;

    13、备份数据库 

    mysqldump -u root -p --opt 数据库名>备份名; //进入到库目录

    14、恢复

    mysql -u root -p 数据库名<备份名; //恢复时数据库必须存在,可以为空数据库

     15、数据库授权

      格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"

    例1、增加一个用户user001密码为123456,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MySQL,然后键入以下命令:

     mysql> grant select,insert,update,delete on *.* to user001@"%" Identified by "123456";

    例2、增加一个用户user002密码为123456,让此用户只可以在localhost上登录,也可以设置指定IP,并可以对数据库test进行查询、插入、修改、删除的操作 (localhost指本地主机,即MySQL数据库所在的那台主机)

            //这样用户即使用知道user_2的密码,他也无法从网上直接访问数据库,只能通过MYSQL主机来操作test库。
            //首先用以root用户连入MySQL,然后键入以下命令:

      mysql>grant select,insert,update,delete on test.* to user002@localhost identified by "123456";
  • 相关阅读:
    新的开始——3.3
    第一个周末——3.2
    恋爱知识大增——周五3.1
    相安无事——周四2.28
    好几天没写了。。。——周三2.27
    开学第二天——2.26
    开学第一天——2.25
    华为
    微软 Microsoft
    谷歌 google
  • 原文地址:https://www.cnblogs.com/lubing666666/p/4259962.html
Copyright © 2011-2022 走看看