zoukankan      html  css  js  c++  java
  • MySQL常用命令

    MySQL创建用户并添加权限的方式:

    1.进入mysql数据库

    mysql -u root mysql
    

    2.在mysql界面添加用户及权限

    create user 'pyjsh'@'localhost' identified by 'pyjsh';
    grant all on *.* to pyjsh@'%' identified by 'pyjsh';
    grant all on *.* to pyjsh@'localhost' identified by 'pyjsh';
    flush privileges;
    

    查询数据库

    show databases;
    

    创建数据库

    create database dbname;
    

    删除数据库

    drop database dbname;
    

    创建数据库表并设置自增长主键

    MariaDB [dyf_da]> create table test_tb
        -> (
        -> id int(11) not null AUTO_INCREMENT primary key,
        -> total int(11),
        -> name varchar(256));
    Query OK, 0 rows affected (0.021 sec)
    

    查看数据表结构

    desc test_tb;
    show columns from test_tb; 和上条命令查询结果一致
    

    向数据表中插入列

    alter table test_tb add column age varchar(256);
    

    修改列的类型

    alter table test_tb modify age int(11);
    

    插入一条新数据

    insert into test_tb(total,name,age) values(34,'tina',23);
    

    修改一条数据记录

    update test_tb set total=15,name='andy',age=22 where id=1;
    

    查询记录数量

     select count(*) from test_tb; 
    

    按关键字查询

    select * from test_tb where name like '%and%';
    

    数据表重命名

    alter table test_tb rename to tb01;
    

    删除数据表中的数据

    delete from tb01 where id=2;
    

    清空数据表:清空后主键id会从1开始递增

    truncate table tb01;
    

    复制一个表

    create table tb2 select * from tb01;
    

    删除数据表

    drop table tb01;
    

    删除数据库

    drop database dyf_da;
    

    本文作者:温茶又折花

    本文链接: https://www.cnblogs.com/dyfblogs/p/11386255.html

    转载文章请注明作者和出处,谢谢!
  • 相关阅读:
    练习2-15 求简单交错序列前N项和(15 分)
    js预解析实例
    one:arguments对象伪数组
    第一章 评估工具
    第6章条件处理
    第五章----过程
    第4章 数据传递.寻址和算术运算
    第3章 汇编语言基础
    第2章-------------IA-32处理器体系结构
    第一章-------基本概念
  • 原文地址:https://www.cnblogs.com/dyfblogs/p/11386255.html
Copyright © 2011-2022 走看看