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

    转载文章请注明作者和出处,谢谢!
  • 相关阅读:
    Centos7安装Python3
    mysql+centos7+主从复制
    Python开发之virtualenv和virtualenvwrapper详解
    Linux基础系统优化(二)
    Linux基础系统优化(一)
    Windows 10版本区别
    HTML5常用的语义化标签
    关于efk多服务器多日志合并收集
    离线状态安装docker容器
    Docker部署jenkins+sonar+gitlab代码检测系统
  • 原文地址:https://www.cnblogs.com/dyfblogs/p/11386255.html
Copyright © 2011-2022 走看看