zoukankan      html  css  js  c++  java
  • Mysql学习---基础操作学习

    1.1. 基本操作

    数据库引擎

    Inodb:支持事务[原子性操作,完成一些列操作后才算完成操作,否则rollback]

    MyISAM: 支持全文索引,强调了快速读取操作,主要用于高负载的select

    创建数据库,表:

    show databases;  # 查看当前Mysql都有那些数据,根目录都有那些文件夹
    create datab  ase 数据库名;  # 创建文件夹
    use 数据库名;  # 使用选中数据库,进入目录
    show tables;  # 查看当前数据库下都有那些表
    create table 表名(nid int, name varchar(20), pwd varchar(64));  # 创建数据库表
    select * from 表名;  # 查看表中的所有数据
    insert into 表名(nid, name, pwd) values(1, 'alex', '123');  # 插入数据
    select * from 表名 where id = 1;

    用户管理特殊命令:

    创建用户
    create user '用户名'@'IP地址' identified by '密码';
    create user 'hhh'@'192.168.25.%' identified by '777';  # 远程连接 %表示通配符
    删除用户
    drop user '用户名'@'IP地址'; 
    修改用户
    rename user'用户名'@'IP地址' to '新用户名'@'IP地址';
    修改密码
    set password for '用户名' @ 'IP地址' = Password('新密码')
    flush privileges;  # 命令即时生效

    权限管理:默认无

    show grants for sh0731@localhost; # 查看权限
    grant all privileges on mysql.test to ftl@localhost; # 授权
    grant all privileges on mysql.user  to hhh@'192.168.25.%';# 远程授权
    revoke all privileges on mysql.test from ftl@localhost; # 收权
    flush privileges;  # 命令即时生效

    远程连接:

    mysql -u root -h 192.168.25.100 -P 3306 –p

    数据库级别操作:

    SHOW DATABASES;
    CREATE DATABASE 数据库名称;
    CREATE DATABASE 数据库名称 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
    USE 数据库名称;
    drop database 数据库名称;

    表级别操作:

    show tables; 
    desc tb1;
    drop table hhh;  # 删除表
    delete from hhh where id = 1; # 清空表内容
    truncate table hhh; # 清空表,但是保留表的框架
    select * from hhh;
    update hhh set sex = 'm' where id = 1;
    create table hhh (
        id  int, 
       name varchar(12),
       sex  varchar(2)
    )

    忘记密码:

    # 启动免授权服务端
    mysqld --skip-grant-tables
    # 客户端
    mysql -u root -p
    # 修改用户名密码
    update mysql.user set authentication_string=password('666') where user='root';
    flush privileges;
  • 相关阅读:
    串行与并行
    并发性和并行性
    循环移位操作
    关于指针
    各种编程语言的特点
    什么是面向过程,什么是面向对象?
    数组指针/指针数组的示例
    数组指针/指针数组
    操作系统判断
    springMVC---简介
  • 原文地址:https://www.cnblogs.com/ftl1012/p/9384604.html
Copyright © 2011-2022 走看看