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

    转载文章请注明作者和出处,谢谢!
  • 相关阅读:
    个人作业——软件评测
    软件工程第五次作业——结对编程的实现
    软件工程第三次作业
    软件工程第一次作业
    两个矩形面积交
    二维并查集
    Java 作业 1
    练习题
    线性表

  • 原文地址:https://www.cnblogs.com/dyfblogs/p/11386255.html
Copyright © 2011-2022 走看看