mysql命令行常用命令_mysql命令行常用命令

net start mysql // 启动mysql服务

net stop mysql // 停止mysql服务

mysql -u root -p //登录mysql数据库

update user set password=password(”xueok654123″) where user=’root’; // 更新用户名为root的登录密码

flush privileges //刷新数据库

use dbname // 使用数据库

show databases; //显示所有数据库

show tables;  //显示数据库中所有的表

describe tablename; //显示表结构

describe user;  //显示数据库中user表的列信息

insert into mysql.user(Host,User,Password) values("localhost","test",password("1234")); //创建一个连接用户(此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录。)

为用户授权:

授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";

指定所有权限给用户:

grant all privileges on testDB.* to test@localhost identified by '1234';  // test用户拥有testDB数据库的所有权限

指定部分权限给用户:

grant select,update on testDB.* to test@localhost identified by '1234';  //test用户拥有testDB数据库的查找和更新权限

指定用户拥有所有数据库的所有权限:

grant all privileges on *.* to test@"%" identified by '1234';  // test用户拥有所有数据库的所有权限(*.*为所有数据库,%表示所有ip地址都可以连接)

指定用户拥有所有数据库的部分权限:

grant select,update,delete,create,drop on *.* to test@localhost identified by '1234';

revoke privileges on databasename.tablename from 'username'@'host';  // 撤销权限

drop user 用户名@ localhost;  //删除用户和权限

update mysql.user set password=password('新密码') where User="test" and Host="localhost";  //修改指定用户的连接密码

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值