资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

mysql数据库基本授权的具体操作流程

下文我给大家简单讲讲关于MySQL数据库基本授权的具体操作流程,大家之前了解过相关类似主题内容吗?感兴趣的话就一起来看看这篇文章吧,相信看完mysql数据库基本授权的具体操作流程对大家多少有点帮助吧。

公司主营业务:网站设计、网站制作、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出黄陂免费做网站回馈大家。

查看mysql数据库的版本
登录数据库查看:
1.用户密码登录时
mysql -uroot -p123456
2.mysql> status;  
3.mysql> select version();  
未登录数据库时查看:
1.mysql --help | grep Distrib    
2.rpm -qa|grep mysql

mysql基本操作和授权:(介绍5.7的和5.6很多地方不一样哦)
MySQL Server version: 5.7.23
本文的数据库test
本文的表名test
本文的用户名test
show databases; 命令查看已经创建了哪些数据库。
show columns from test 或者desc test;获取表结构命令:
shou tables 查看所有的表
use database1; 切换数据库
show grants;  查看当前用户的权限
show grants for test@"%";  查看其它用户的权限,test@"%"代表user表中的user和host字段
flush privileges; 刷新系统权限
mysql中没有像oracle set line 100 pages 9999的设置,可以在最后加入\G
例如:select * from user\G;

mysql -h 主机名 -u 用户名 -p
-p:密码登录, 如果登录的用户名密码为空, 可以忽略此选项。
-D:所选择的数据库名

重置mysql的数据库密码
1、首先停掉mysql 数据库 一般是安装在/etc/init.d/mysqld stop
2、修改mysql的配置文件 /etc/my.cnf  
最后一行添加 skip-grant-tables 表示可以跳过权限去登录
3、重启 mysql 数据库 /etc/init.d/mysqld start
3、使用 mysql -u root -p
4、修改root密码。
update user set password=PASSWORD("123456") where user='root';
5、修改配置文件删除或禁用skip-grant-tables这行。
注:mysql的数据库老版本用参数authentication_string,新版本用参数password
update user set authentication_string=password('123456') where user='root';
update user set password=password('123456') where user='root';
flush privileges; --刷新系统权限表

创建数据库
create database test character set gbk;
测试建表
create table test(id int,name varchar(20),bianma varchar(20));
INSERT INTO test VALUES (1,'tom1','13211');
INSERT INTO test VALUES (2,'tom2','13212');
INSERT INTO test VALUES (3,'tom3','13213');
INSERT INTO test VALUES (4,'tom4','13214');

删除数据库
drop database test_database;
删除表
drop table test_tab;

创建用户命令:
GRANT USAGE ON . TO 'test'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
或者
create user 'test1'@'%' identified by '123456';
两条命令都可以,用户名test密码是123456

删除用户命令:
mysql> drop user 'test1'@'%'
mysql> drop user 'test'@'localhost'
注意删除格式:'user'@'host'

mysql数据库授权:
grant 权限 on 数据库对象 to 用户
权限:增删改查, insert,delete,update,select,create,alter,drop,all等
references 外键权限,create temporary 创建临时表权限,index 创建索引权限,create view和show view 创建视图和查看视图权限,create routine和alter routine 创建和修改存储过程权限,execute 操作函数权限,
数据库对象:表名,数据库名.表名,test.,.*等
用户:要取得权限的用户,test,test@localhost,test@"%",格式的意思是user表中的user和host

授权用户test只查看表test中的两个字段的权限
grant select(name,id) on test to test@'%' ;

授权test用户拥有test数据库的所有权限:
grant all privileges on test. to test@localhost identified by '123456'; --privileges可省略不写
grant all on test. to test@localhost;
授权部分权限给用户
grant select,update on test. to test@localhost identified by '123456';
grant select,update on test. to test@localhost ;

授权test用户拥有所有数据库的某些权限:  
grant select,delete,update,create,drop on . to test@"%" identified by "123456";
或者
grant all on test.* to test@localhost;

test用户可以将test数据库中的所有表的select权限授权给其它用户
grant select on test. to test with grant option;
注:以上例句将替换成表名,将test数据库中的某个表作为数据库对象

取消授权,撤销授权,授权收回
revoke all on . from test;
授权和取消授权的语句基本一致,将grant和revoke互换,from和to互换就可以。
取消授权
revoke select on . from test;
授权
grant select on . to test;

mysql能够像Oracle的sqlplus那样设置pagesize和linesize
select * from table_name\G;

mysql delete中where后能套用select
delete test_user from test_user a, (select id from test_user where id < 10) b
where a.id = b.id

表数据太大只查看5行
select from gp_plat_user where rownum < 6;
select from gp_plat_user limit 6;

错误集锦:
报错1.Ignoring query to other database
mysql> show databases;
Ignoring query to other database
mysql> show user;
Ignoring query to other database
方案:
登录的使用参数 -u
报错2.
ERROR 1130 (HY000): Host '10.1.1.10' is not allowed to connect to this MySQL server
[root@master logs]# mysql -uroot -p123456 -h 10.1.1.10
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1130 (HY000): Host '10.1.1.10' is not allowed to connect to this MySQL server
方案:跳过密码登录,修改数据库中的host字段

mysql> select host,user from user where user='root';
+-----------+------+
| host      | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> commit;      --这个命令也可以提交哦
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user where user='root';
+------+------+
| host | user |
+------+------+
| %    | root |
+------+------+
1 row in set (0.00 sec)

报错3.
登录时报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
方案:mysql -uroot -p123456
报错4.登录后查询数据库报错:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示说让操作之前先要用命令ALTER USER修改密码
我使用下面的alter命令修改后,不好使,就用set修改的,修改完后可以使用。
方案: alter user 'root'@'localhost' identified by '123456';  --不好使
set password=password("123456"); --好使

错误5.
mysql> insert into user(Host,User,authentication_string) values("localhost","test",password("123456"));
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
方案: set global validate_password_policy=0;
set global validate_password_length=1;
查看的方法:select @@validate_password_policy;
select @@validate_password_length;
详情可以看这个技术博主https://www.cnblogs.com/ivictor/p/5142809.html

错误6.
mysql> insert into user(Host,User,authentication_string) values("localhost","test",password("123456"));
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
报错ssl_cipher字段不能为空,mysql添加用户不能直接insert user表中。
方案:网上说修改配置文件my.cnf中由
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES改为:sql_mode=NO_ENGINE_SUBSTITUTION
对于5.7版本的mysql不好使,使用如下的命令进行创建新用户好使
GRANT USAGE ON . TO 'test'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> GRANT USAGE ON . TO 'test'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| test          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
错误7:
[root@master logs]# mysql -utest -ptest
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'test'@'localhost' (using password: YES)
方案:和错误2一样
修改host:update user set host = '%' where user = 'test';

navicat的快捷键:
Ctrl+Q、Ctrl+N            打开查询窗口
Ctrl+/            注释sql语句
Ctrl+Shift +/  解除注释
Ctrl+R           运行查询窗口的sql语句
F6               打开一个mysql命令行窗口
Ctrl+L           删除一行
Ctrl+W          关闭一个查询窗口
Ctrl+D         表的数据显示显示页面切换到表的结构设计页面,但是在查询页面写sql时是复制当前行

和权限有关的几张表

大家觉得mysql数据库基本授权的具体操作流程这篇文章怎么样,是否有所收获。如果想要了解更多相关,可以继续关注我们的行业资讯板块。


分享文章:mysql数据库基本授权的具体操作流程
文章来源:http://cdkjz.cn/article/pcesco.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220