MySQL常用命令

1、登录

mysql -u root -p密码
mysql -u root -p
mysql -hlocalhost -uroot -p

2、清屏

cls

3、操作用户

# 查看现有用户
select host,user,authentication_string from mysql.user;
# 新建用户
# create user "username"@"host" identified by "password";
# host="localhost"为本地登录用户,host="ip"为ip地址登录,host="%",为外网ip登录
create user 'test'@'localhost' identified by '123';
create user 'test'@'192.168.46.120' identified by '123';
create user 'test'@'%' identified by '123';
# 删除用户
drop user 'username'@'host';
# 更改用户名
rename user 'test'@'%' to 'dev'@'%';
# 修改密码
# 1、
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
# 2、格式:mysqladmin -u用户名 -p旧密码 password 新密码
mysqladmin -uroot -p123456 password 1234abcd
# 3、用update直接编辑user表
# 4、
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

4、授权

# grant privileges on databasename.tablename to 'username'@'host' IDENTIFIED BY 'PASSWORD';

# 授予用户通过外网IP对于该数据库的全部权限
grant all privileges on `test`.* to 'test'@'%' ;
# 授予用户在本地服务器对该数据库的全部权限
grant all privileges on `test`.* to 'test'@'localhost';   
# 给予查询权限
grant select on test.* to 'user1'@'localhost';
# 添加插入权限
grant insert on test.* to 'user1'@'localhost';
# 添加删除权限
grant delete on test.* to 'user1'@'localhost';
# 添加更新权限
grant update on test.* to 'user1'@'localhost';
# 刷新权限
flush privileges;
# 查看权限
show grants;
# 查看某个用户的权限
show grants for 'test'@'%';
# 删除权限
revoke delete on test.* from 'test'@'localhost';
# 刷新权限
flush privileges;

5、查看默认数据库密码

cat /var/log/mysqld.log | grep password

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值