热门搜索 :
考研考公
您的当前位置:首页正文

mysql 设置账户权限

2023-11-09 来源:东饰资讯网

会提示可以运行mysql_secure_installation。运行mysql_secure_installation会执行几个设置:a)为root用户设置密码b)删除匿名账号c)取消root用户远程登录d)删除test库和对test库的访问权限e)刷新授权表使修改生效通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation,详细步骤请参看下面的命令:复制代码代码如下:[root@server1 ~]#mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT ISRECOMMENDED FOR ALL MySQLSERVERS IN PRODUCTION USE! PLEASE READ EACH STEPCAREFULLY!In order to log into MySQL to secure it, we‘ll need thecurrentpassword for the root user. If you‘ve just installed MySQL,andyou haven""t set the root password yet, the password will be blank,soyou should just press enter here.Enter current password for root (enter fornone):<–初次运行直接回车OK, successfully usedpassword, moving on…Setting the root password ensures that nobody can loginto the MySQLroot user without the proper authorisation.Set rootpassword? [Y/n] <–是否设置root用户密码,输入y并回车或直接回车New password: <– 设置root用户的密码Re-enter new password: <– 再输入一次你设置的密码Password updatedsuccessfully!Reloading privilege tables..… Success!By default, aMySQL installation has an anonymous user, allowing anyoneto log into MySQLwithout having to have a user account created forthem. This is intended onlyfor testing, and to make the installationgo a bit smoother. You shouldremove them before moving into aproduction environment.Remove anonymoususers? [Y/n] <–是否删除匿名用户,生产环境建议删除,所以直接回车… Success!Normally, root should only beallowed to connect from ‘localhost‘. Thisensures that someone cannot guessat the root password from the network.Disallow root login remotely?[Y/n]<–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止… Success!By default, MySQLcomes with a database named ‘test‘ that anyone canaccess. This is alsointended only for testing, and should be removedbefore moving into aproduction environment.Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车- Dropping testdatabase…… Success! 查看用户表mysql> select host,user,password from mysql.user;+---------------+-------+-------------------------------------------+| host          | user  | password                                  |+---------------+-------+-------------------------------------------+| localhost          | root  | *C9A034778FB438CDECD150408139516FEBC8FA5B || 127.0.0.1         | root  | *C9A034778FB438CDECD150408139516FEBC8FA5B || ::1                  | root  | *C9A034778FB438CDECD150408139516FEBC8FA5B || 192.168.1.104 | slave | *E56A114692FE0DE073F9A1DD68A00EEB9703F3F1 |+---------------+-------+-------------------------------------------+在mysql库mysql> use mysqlDatabase changed;修改root用户登陆密码mysql> update mysql.user set password = password(‘gaofei‘) where user=‘root‘;刷新授权表  或者退出mysql重启mysql> flush privileges;如果忘记密码了就:修改配置文件vi /etc/my.cnf搜索 :/mysqld 在他下面这一行添加 skip-grant-tables  跳过权限验证 [mysqld]skip-grant-tables重启myslqservice mysql restart在进入mysql的时候就不用输密码了 这时在执行刚才的修改密码 这样密码就能修改了 修改好之后要删除刚才在配置项中添加的skip-.. 命令 不然密码形同虚设添加一个用户all 代表可执行的操作 比如delete/alter/insert等  *.*是执行范围 ‘所有表.所有数据库‘ ‘lisi‘是账号 ‘localhost‘是ip  最后那个是登陆密码mysql> grant all on *.* to ‘lisi‘@‘localhost‘ identified by ‘123123‘;刷新授权表 或重启mysqlmysql> flush privileges;创建一个测试数据库和表 添加个数据mysql> create database hd charset utf8;mysql> use hd;mysql> create table stu(id int,name char(20));mysql> insert into stu set id=1,name=12123;添加一个只有查看权限的用户mysql> grant select on hd.* to ‘wangwu‘@‘localhost‘ identified by ‘123123‘;添加完以后一定要刷新权限表 这样刚添加的账户立即生效  然后用 wangwu登陆的时候就只有hd库中所有表的查看权限了  ‘localhost‘代表本地主机  可以设置成其他ip的 也可以设置成任何ip的‘%‘  ‘wangwu‘@‘%‘  这样就说明只要是叫wangwu的都只有查看权限了因此也能看出账号同名同密码都可以 因为抓取的地址不同那么他所拥有的权限也会不同 如下:mysql> grant select on hd.* to ‘wangwu‘@‘192.168.1.1‘ identified by ‘123123‘;mysql> grant delete on hd.* to ‘wangwu‘@‘192.168.1.2‘ identified by ‘123123‘;

mysql 设置账户权限

标签:

小编还为您整理了以下内容,可能对您也有帮助:

mysql怎么设置用户权限?

增加一个用户test1 密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。

首先用以root 用户连入MySQL,然后键入以下命令:

mysql>grant select,insert,update,
delete on *.* to test2@localhost identified by \"abc\";

grant命令:

创建一个可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令something 做这个:

mysql> grant all privileges on *.* to user@localhost identified
by ’something’ with GRANT OPTION;

mysql怎么设置用户权限?

增加一个用户test1 密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。

首先用以root 用户连入MySQL,然后键入以下命令:

mysql>grant select,insert,update,
delete on *.* to test2@localhost identified by \"abc\";

grant命令:

创建一个可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令something 做这个:

mysql> grant all privileges on *.* to user@localhost identified
by ’something’ with GRANT OPTION;

如何设置mysql用户的权限

1、创建新用户

通过root用户登录之后创建

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  创建新用户,用户名为testuser,密码为123456 ;

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,可以在本地访问mysql

>> grant all privileges on *.* to testuser@"%" identified by "123456" ;   //  设置用户testuser,可以在远程访问mysql

>> flush privileges ;  //  mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

2、设置用户访问数据库权限

>> grant all privileges on test_db.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,只能访问数据库test_db,其他数据库均不能访问 ;

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  设置用户testuser,可以访问mysql上的所有数据库 ;

>> grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;  //  设置用户testuser,只能访问数据库test_db的表user_infor,数据库中的其他表均不能访问 ;

3、设置用户操作权限

>> grant all privileges on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;  //设置用户testuser,拥有所有的操作权限,也就是管理员 ;

>> grant select on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION ;  //设置用户testuser,只拥有【查询】操作权限 ;

>> grant select,insert on *.* to testuser@localhost identified by "123456" ;  //设置用户testuser,只拥有【查询\插入】操作权限 ;

>> grant select,insert,update,delete on *.* to testuser@localhost identified by "123456" ;  //设置用户testuser,只拥有【查询\插入】操作权限 ;

>> REVOKE select,insert ON what FROM testuser  //取消用户testuser的【查询\插入】操作权限 ;

如何用phpmyadmin设置mysql数据库用户的权限

mysql数据库用户的权限如何设置?考虑到数据库的安全在将数据库的登录名和密码给别人时我们通常都需要为用户设置数据库的权限,那么mysql数据库用户的权限如何设置呢?小编为大家带来了用phpmyadmin设置数据库权限的方法。

一、首先您需要安装配置phpMyAdmin到您的服务器

安装好以后,来到 phpMyAdmin 的首页

二、创建好的用户,点击上图上的权限后,可以看到添加新用户

点击“添加新用户”添加一个新的数据库用户名

如下图所示:

三、权限设置

编辑这个用户的权限

如下图所示:

其中增加用户的同时也可以填写用户的权限,也可以添加完用户以后再编辑用户的权限

下面对这些权限进行详细的描述:

1、数据部分

SELECT:是指允许读取数据

INSERT:是指允许插入和替换数据

UPDATE:是指允许更改数据

DELETE:是指允许删除数据

FILE:是指允许从数据中导入数据,以及允许将数据导出至文件

2、结构部分

CTEATE:允许创建新的数据库和表

ALTER:允许修改现有表的结构

INDEX:允许创建和删除索引

DROP:允许删除数据库和表

CREATE TEMPORARY TABLES:允许创建暂时表

CREATE VIEW:允许创建新的视图

SHOW VIEW:允许查询试图

CREATE ROUTINE:允许创建新的存储过程

ALTER ROUTINE:允许修改存储过程

EXECUTE:允许执行查询

管理和资源这里不详细说明了,一般是管理员 root 帐号全部有的权限,上面所讲的是普通的用户权限。

四、重新加载授权表

修改完用户权限以后需要回到首页,重新加载一下授权

Top