MySQL常用命令

在cmd命令行中的操作,需要先登录MySQL

无密码:mysql -u root

有密码:mysql -u root -p  (会提示输入数据库密码)

如果直接在mysql命令行中操作,则没有登录MySQL这一步。

MySQL常用命令:

一、操作数据库和数据表:

  • 显示数据库:show databases;
  • 创建数据库: create database 数据库名;   
  • 切换数据库:use 数据库名;
  • 显示数据库中的表:show tables from 数据库名; 
  • 列出所有表:show tables;
  • 显示数据表结构:describe 表名;
  • 进入mmall数据库中,创建表:
    mysql> use mmall
    Database changed
    mysql> create table table_01(
        -> id INT NOT NULL AUTO_INCREMENT,
        -> title VARCHAR(100) NOT NULL,
        -> PRIMARY KEY (id)
        -> );
    Query OK, 0 rows affected (0.10 sec)
  • 删除数据库:drop database 数据库名;
  • 删除数据表:drop table 数据表名;

二、查看、删除、插入、刷新用户:

  • 查找目前mysql的用户:select user,host,password from mysql.user;

       

  • 删除mysql的用户:delete from mysql.user where user='yourusername';
  • 插入mysql新用户: insert into mysql.user(Host,User,Password) values("localhost","test",password("root"));                        在一些mysql版本下,需要这样插入:grant usage on *.* to 'yourusername'@localhost identified by 'yourpassword' with grant option;
  • 刷新,使操作生效:flush privileges

三、 修改指定用户(root)密码

  • mysql -u root -p

        输入密码

        set password from root@localhost=password('yourpassword');

四、 为用户授权

  • 授权test用户拥有mmall数据库的所有权限:

   grant all privileges on mmall.* to test@localhost identified by 'yourpassword';

  • 授权test用户拥有指定的部分权限:

   grant select,update on mmall.* to test@localhost identified by 'yourpassword';

  • 授权test用户拥有所有数据库的某些权限:  

   grant select,delete,update,create,drop on *.* to test@"%" identified by "yourpassword";

  • 给test用户开通外网所有权限:

        grant all privileges on mmall.* to test@"%" identified by "yourpassword";

  • 给test用户开通指定ip地址的增改查权限

        grant select,insert,update on mmall.* to test@'192.11.11.11' identified by "yourpassword";

五、 其它

  • 退出mysql:exit
  • 查看mysql版本:select version();

      

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值