mysql 创建用户1805,Mysql用户&权限管理

1、创建用户(相关表mysql.user)localhostroot本机

127.0.0.1root本机

::1root本机

%cheng远程用户(任意ip)

192.168.1.55jake远程用户(指定ip)

1).创建本地用户(只能在本机登陆本机数据库)

create user 'cheng'@'localhost' identified by '123456';指定密码"123456".

insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));

在新版本已经不能这样直接使用了,会提示某些字段不能为空。还是create user方便。

2).创建远程用户(其他计算机用户可通过此用户来访问这个数据库)

create user 'name'@'%' identified by 'password';

"%"代表任意的远程用户

3).修改用户密码:

update `mysql`.`user` set password = password('123456') where user = ‘cheng' and host = 'localhost’;

set password for 'cheng'@'localhost' = password('778478635’);

set password for = password('778478635’);给自己改密码

4).mysql登录:

1 mysql -u root -h IP -p password 本地登录时“-h IP”可省略。

2 默认安装完的root@localhost用户没有密码

3 匿名用户只有USAGE的权限,只能登陆,无其他权限

5).其他:

1 GRANT USAGE ON *.* TO ''@‘localhost' 仅允许登录,无其他权限,最低权限

2 status(\s)查看当前各种信息

3 show character set;查看字符集

4 select * from mysql.user\G 按列显示数据

5 mysql一开始默认账号有root和匿名账号,匿名账号就是无论什么用户名都可以登录

6 "create user jake" 相当于create user 'jake'@'%';这名用户可从任意远程客户端登录

7 create user 'cheng'@'localhost' identified by '123456';本地的cheng用户

8 create user 'cheng'@'192.168.1.15' identified by '123456';指定ip地址的cheng用户

2、权限管理

1).用户授权:

1 grant select,alter on 'cheng'@'localhost' identified by '123'

2 grant all (privileges) on 'cheng'@'localhost' 授予全部权限

3 GRANT SELECT ON `mysql`.`user` TO 'www'@'localhost' 仅具备user表的select权限

4 GRANT USAGE ON *.* TO 'discuz'@'localhost' IDENTIFIED BY PASSWORD(仅登录权限)

5 “*.*”表示所有库的所有表,也可以指定库指定表“mysql.user”。

6 GRANT语句后加上“with grant option”表示同时赋予相关表的授权资格。

7 grant 一个不存在的用户名,会直接创建改用户

2).撤销用户权限

revoke all on mysql.user from 'cheng'@'localhost’;

revoke select,update on mysql.user from 'cheng'@'localhost’;

3).查看指定用户权限

show grants for cheng@localhost;//指定用户的权限

show grants;

show grants for current_user;//查看自己的权限

show grants for current_user();

3、删除用户

1 drop user 'jake'@'localhost';//删除数据库

2 drop table tb_name;//删除表

3 drop database db_name;//删除数据库

4.其他

1)、eclipse链接数据库

show view --> Data Source Explorer

Database Connections 新建数据库链接

选择mysql驱动"mysql-connector-java-5.1.8-bin.jar”

2)、登陆后,source filename.sql(执行语句,导入外部数据)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值