永发信息网

请问,linux下mysql创建用户,具有所有数据库所有表并且具有所有操作的权限,并且可远程登录操作

答案:6  悬赏:30  手机版
解决时间 2021-03-31 09:36
  • 提问者网友:十年饮冰
  • 2021-03-30 12:42
我以root身份登录后执行
grant all privileges on *.* to test1@'%' identified by 'tests';
出现
Query OK, 0 rows affected (0.00 sec)
然后我退出登录就会报
ERROR 1045 (28000): Access denied for user 'test1'@'localhost'
请问这是何种缘故?
希望有经验的开发人员或者DBA帮我解决下。因为这是涉及到商业环境搭建。希望能给一个比较靠谱的解决方案。
高分求。不胜感激~~
最佳答案
  • 五星知识达人网友:第幾種人
  • 2020-05-22 09:45
可以找个免费/开源的客户端来使用,例如HeidiSQL或者Navicat Lite,你搜一下就能找到。
安装后在里面设置好连接(主要是填一下服务器地址、用户名及帐号)就能可以使用了(服务器端可能也需要设置赋予权限,不然就会出现类似“ERROR 1045 (28000): Access denied for user 'test1'@'localhost”这样的错误,如出现错误则见参考资料)。
默认root用户就具有所有的权限,你可以新建一个用户,使它拥有所有的权限,还可以指定从什么地方登陆。权限划分可以很细的,可以精确到table,像select这种简单的查看功能命令都可以限定。具体命令像create,grant等等可以找本书看看。用户访问权限:

mysql.user 全局层级权限(global privileges)
db 数据库层级(database-specific privileges)
tables_priv 表层级(table-secific privileges)
columns_priv 列层级(column-secific privileges)

新建用户
create user 'test1'@'localhost/127.0.0.1' identified by '123',
->'test2'@'%' identified by '123';
语法: create user 'user'[@'host'] [identified by [password] 'password']

删除用户
drop user 'test1'@'localhost','test1'@'%','test2'@'localhost';
语法: drop user 'user'@'host'

撤销用户权限
revoke all on *.* from 'test'@'localhost';

更改用户名
rename user 'test'@'localhost' to 'test1'@'%';

用户授权
grant all privileges on *.*/dbname.*/dbname.tablename/ to 'test'@'localhost' identified by '123'
->required ssl with grant option;
grant select,update(field1,field2) on dbname.tablename to 'test1'@'%' identified by '123'
->required ssl with grant option;

搜索得到一位前辈的解决办法如下:
首先,在连接jdbc驱动的时候,按如下语句:
String connstr ="jdbc:mysql://localhost:3306/tp_db?&useUnicode=true&characterEncoding=8859_1";
然后,输入中文时转换时,按如下语句:
sql=new String(sql.getBytes("iso8859-1"));
最后,输出中文时转换,按如下语句:
String bookname=new String(rs.getString("bookname").getBytes("iso8859-1"),"GBK或者GB2312");

注:查看显示结果应在中文支持的环境下,我的配置为:Linux7.3+Tomcat4.0+Mysql3.22 作服务器端,IE6或Netscape作浏览器。
全部回答
  • 1楼网友:底特律间谍
  • 2020-11-25 01:27
我们都是菜菜你不应该把这种问题方到这里提问,还搞这么多分在这里诱惑人是何居心??
  • 2楼网友:西风乍起
  • 2020-05-05 12:24
grant all privileges on *.* to test1@'%' identified by 'tests'; 上面的语句回车后输入下面的语句,然后回车,再退出 flush privileges;
  • 3楼网友:愁杀梦里人
  • 2019-12-25 14:36
语句看上去没有错啊,你grant后用 flush privileges; 另外,可以用select命令到mysql库里面的user表中看看test1这个用户设置是否正确,包括host字段的内容
  • 4楼网友:拾荒鲤
  • 2019-11-02 22:25
hi 楼主,在数据库中创建包含很多,视图,索引,临时表的创建权限都能分开赋予,你可以执行 show privileges 来查看权限参数,我这边就以创建表为例,只包含查询表功能,其他修改,删除,备份没有权限;以下是步骤: 1,create user 'tom'@'%' identified by '123456';---创建用户,无权限; 2, grant create,select on wangxh2.* to tom;-----把wangxh2库的所有表的创建和查询赋予tom 3,flush privileges;-----刷新权限表才能起效 接下来是测试: mysql> show databases; +--------------------+ | database | +--------------------+ | information_schema | | test | | wangxh2 | +--------------------+ 3 rows in set (0.06 sec) mysql> use wangxh2 database changed mysql> show tables; +-------------------+ | tables_in_wangxh2 | +-------------------+ | test | +-------------------+ 1 row in set (0.00 sec) mysql> drop test; error 1064 (42000): you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'test' at line 1 mysql> drop table test; error 1142 (42000): drop command denied to user 'tom'@'localhost' for table 'test' mysql> select count(*) from test; +----------+ | count(*) | +----------+ | 33554432 | +----------+ 1 row in set (0.01 sec) mysql> insert into test values(1); error 1142 (42000): insert command denied to user 'tom'@'localhost' for table 'test' mysql> delete from test; error 1142 (42000): delete command denied to user 'tom'@'localhost' for table 'test' mysql> update test set id=1; error 1142 (42000): update command denied to user 'tom'@'localhost' for table 'test' mysql> create table test1 (id int); query ok, 0 rows affected (0.02 sec) mysql> insert into test1 values(1); error 1142 (42000): insert command denied to user 'tom'@'localhost' for table 'test1' [mysql@localhost ~]$ mysqldump -u tom -paidengshan wangxh2 >/home/mysql/aa.sql mysqldump: got error: 1044: access denied for user 'tom'@'%' to database 'wangxh2' when using lock tables [mysql@localhost ~]$ ----------------------------------------------------------------------------------------- 以上测试发现,tom对wangxh2有建表,查询表的权限,但是修改,删除,新增,备份都没有权限,达到你的需求了
  • 5楼网友:独行浪子会拥风
  • 2020-07-05 09:22
出现这个情况需要注意2点: 1、当前虽然进行用户授权了,但是没有对权限表进行刷新,这样权限操作不会生效,请在mysql命令行执行如下命令 flush privileges;2、通过错误的显示来看,test1用户本地权限的访问没有开通,可以创建test1用户localhost访问的权限并执行第1点的刷权限命令; 注:如果第2点你不想添加,可以通过mysql客户端指定IP访问mysql server,例如: mysql  -h ip  -uroot  -ppassword
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯