溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql數(shù)據(jù)庫基本授權的具體操作流程

發(fā)布時間:2020-06-05 15:33:00 來源:網(wǎng)絡 閱讀:369 作者:三月 欄目:系統(tǒng)運維

下文我給大家簡單講講關于mysql數(shù)據(jù)庫基本授權的具體操作流程,大家之前了解過相關類似主題內(nèi)容嗎?感興趣的話就一起來看看這篇文章吧,相信看完mysql數(shù)據(jù)庫基本授權的具體操作流程對大家多少有點幫助吧。

查看mysql數(shù)據(jù)庫的版本
登錄數(shù)據(jù)庫查看:
1.用戶密碼登錄時
mysql -uroot -p123456
2.mysql> status;  
3.mysql> select version();  
未登錄數(shù)據(jù)庫時查看:
1.mysql --help | grep Distrib    
2.rpm -qa|grep mysql

mysql基本操作和授權:(介紹5.7的和5.6很多地方不一樣哦)
MySQL Server version: 5.7.23
本文的數(shù)據(jù)庫test
本文的表名test
本文的用戶名test
show databases; 命令查看已經(jīng)創(chuàng)建了哪些數(shù)據(jù)庫。
show columns from test 或者desc test;獲取表結構命令:
shou tables 查看所有的表
use database1; 切換數(shù)據(jù)庫
show grants;  查看當前用戶的權限
show grants for test@"%";  查看其它用戶的權限,test@"%"代表user表中的user和host字段
flush privileges; 刷新系統(tǒng)權限
mysql中沒有像oracle set line 100 pages 9999的設置,可以在最后加入\G
例如:select * from user\G;

mysql -h 主機名 -u 用戶名 -p
-p:密碼登錄, 如果登錄的用戶名密碼為空, 可以忽略此選項。
-D:所選擇的數(shù)據(jù)庫名

重置mysql的數(shù)據(jù)庫密碼
1、首先停掉mysql 數(shù)據(jù)庫 一般是安裝在/etc/init.d/mysqld stop
2、修改mysql的配置文件 /etc/my.cnf  
最后一行添加 skip-grant-tables 表示可以跳過權限去登錄
3、重啟 mysql 數(shù)據(jù)庫 /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的數(shù)據(jù)庫老版本用參數(shù)authentication_string,新版本用參數(shù)password
update user set authentication_string=password('123456') where user='root';
update user set password=password('123456') where user='root';
flush privileges; --刷新系統(tǒng)權限表

創(chuàng)建數(shù)據(jù)庫
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');

刪除數(shù)據(jù)庫
drop database test_database;
刪除表
drop table test_tab;

創(chuàng)建用戶命令:
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數(shù)據(jù)庫授權:
grant 權限 on 數(shù)據(jù)庫對象 to 用戶
權限:增刪改查, insert,delete,update,select,create,alter,drop,all等
references 外鍵權限,create temporary 創(chuàng)建臨時表權限,index 創(chuàng)建索引權限,create view和show view 創(chuàng)建視圖和查看視圖權限,create routine和alter routine 創(chuàng)建和修改存儲過程權限,execute 操作函數(shù)權限,
數(shù)據(jù)庫對象:表名,數(shù)據(jù)庫名.表名,test.,.*等
用戶:要取得權限的用戶,test,test@localhost,test@"%",格式的意思是user表中的user和host

授權用戶test只查看表test中的兩個字段的權限
grant select(name,id) on test to test@'%' ;

授權test用戶擁有test數(shù)據(jù)庫的所有權限:
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用戶擁有所有數(shù)據(jù)庫的某些權限:  
grant select,delete,update,create,drop on . to test@"%" identified by "123456";
或者
grant all on test.* to test@localhost;

test用戶可以將test數(shù)據(jù)庫中的所有表的select權限授權給其它用戶
grant select on test. to test with grant option;
注:以上例句將替換成表名,將test數(shù)據(jù)庫中的某個表作為數(shù)據(jù)庫對象

取消授權,撤銷授權,授權收回
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

表數(shù)據(jù)太大只查看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
方案:
登錄的使用參數(shù) -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
方案:跳過密碼登錄,修改數(shù)據(jù)庫中的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.登錄后查詢數(shù)據(jù)庫報錯:
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表中。
方案:網(wǎng)上說修改配置文件my.cnf中由
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES改為:sql_mode=NO_ENGINE_SUBSTITUTION
對于5.7版本的mysql不好使,使用如下的命令進行創(chuàng)建新用戶好使
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         表的數(shù)據(jù)顯示顯示頁面切換到表的結構設計頁面,但是在查詢頁面寫sql時是復制當前行

和權限有關的幾張表

大家覺得mysql數(shù)據(jù)庫基本授權的具體操作流程這篇文章怎么樣,是否有所收獲。如果想要了解更多相關,可以繼續(xù)關注我們的行業(yè)資訊板塊。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI