下文我給大家簡單講講關(guān)于MySQL數(shù)據(jù)庫基本授權(quán)的具體操作流程,大家之前了解過相關(guān)類似主題內(nèi)容嗎?感興趣的話就一起來看看這篇文章吧,相信看完mysql數(shù)據(jù)庫基本授權(quán)的具體操作流程對大家多少有點(diǎn)幫助吧。
公司主營業(yè)務(wù):網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出黃陂免費(fèi)做網(wǎng)站回饋大家。
查看mysql數(shù)據(jù)庫的版本
登錄數(shù)據(jù)庫查看:
1.用戶密碼登錄時(shí)
mysql -uroot -p123456
2.mysql> status;
3.mysql> select version();
未登錄數(shù)據(jù)庫時(shí)查看:
1.mysql --help | grep Distrib
2.rpm -qa|grep mysql
mysql基本操作和授權(quán):(介紹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;獲取表結(jié)構(gòu)命令:
shou tables 查看所有的表
use database1; 切換數(shù)據(jù)庫
show grants; 查看當(dāng)前用戶的權(quán)限
show grants for test@"%"; 查看其它用戶的權(quán)限,test@"%"代表user表中的user和host字段
flush privileges; 刷新系統(tǒng)權(quán)限
mysql中沒有像oracle set line 100 pages 9999的設(shè)置,可以在最后加入\G
例如:select * from user\G;
mysql -h 主機(jī)名 -u 用戶名 -p
-p:密碼登錄, 如果登錄的用戶名密碼為空, 可以忽略此選項(xiàng)。
-D:所選擇的數(shù)據(jù)庫名
重置mysql的數(shù)據(jù)庫密碼
1、首先停掉mysql 數(shù)據(jù)庫 一般是安裝在/etc/init.d/mysqld stop
2、修改mysql的配置文件 /etc/my.cnf
最后一行添加 skip-grant-tables 表示可以跳過權(quán)限去登錄
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)權(quán)限表
創(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ù)庫授權(quán):
grant 權(quán)限 on 數(shù)據(jù)庫對象 to 用戶
權(quán)限:增刪改查, insert,delete,update,select,create,alter,drop,all等
references 外鍵權(quán)限,create temporary 創(chuàng)建臨時(shí)表權(quán)限,index 創(chuàng)建索引權(quán)限,create view和show view 創(chuàng)建視圖和查看視圖權(quán)限,create routine和alter routine 創(chuàng)建和修改存儲過程權(quán)限,execute 操作函數(shù)權(quán)限,
數(shù)據(jù)庫對象:表名,數(shù)據(jù)庫名.表名,test.,.*等
用戶:要取得權(quán)限的用戶,test,test@localhost,test@"%",格式的意思是user表中的user和host
授權(quán)用戶test只查看表test中的兩個(gè)字段的權(quán)限
grant select(name,id) on test to test@'%' ;
授權(quán)test用戶擁有test數(shù)據(jù)庫的所有權(quán)限:
grant all privileges on test. to test@localhost identified by '123456'; --privileges可省略不寫
grant all on test. to test@localhost;
授權(quán)部分權(quán)限給用戶
grant select,update on test. to test@localhost identified by '123456';
grant select,update on test. to test@localhost ;
授權(quán)test用戶擁有所有數(shù)據(jù)庫的某些權(quán)限:
grant select,delete,update,create,drop on . to test@"%" identified by "123456";
或者
grant all on test.* to test@localhost;
test用戶可以將test數(shù)據(jù)庫中的所有表的select權(quán)限授權(quán)給其它用戶
grant select on test. to test with grant option;
注:以上例句將替換成表名,將test數(shù)據(jù)庫中的某個(gè)表作為數(shù)據(jù)庫對象
取消授權(quán),撤銷授權(quán),授權(quán)收回
revoke all on . from test;
授權(quán)和取消授權(quán)的語句基本一致,將grant和revoke互換,from和to互換就可以。
取消授權(quán)
revoke select on . from test;
授權(quán)
grant select on . to test;
mysql能夠像Oracle的sqlplus那樣設(shè)置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;
錯(cuò)誤集錦:
報(bào)錯(cuò)1.Ignoring query to other database
mysql> show databases;
Ignoring query to other database
mysql> show user;
Ignoring query to other database
方案:
登錄的使用參數(shù) -u
報(bào)錯(cuò)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; --這個(gè)命令也可以提交哦
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)
報(bào)錯(cuò)3.
登錄時(shí)報(bào)錯(cuò):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
方案:mysql -uroot -p123456
報(bào)錯(cuò)4.登錄后查詢數(shù)據(jù)庫報(bào)錯(cuò):
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示說讓操作之前先要用命令A(yù)LTER USER修改密碼
我使用下面的alter命令修改后,不好使,就用set修改的,修改完后可以使用。
方案: alter user 'root'@'localhost' identified by '123456'; --不好使
set password=password("123456"); --好使
錯(cuò)誤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;
詳情可以看這個(gè)技術(shù)博主https://www.cnblogs.com/ivictor/p/5142809.html
錯(cuò)誤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
報(bào)錯(cuò)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不好使,使用如下的命令進(jìn)行創(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)
錯(cuò)誤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)
方案:和錯(cuò)誤2一樣
修改host:update user set host = '%' where user = 'test';
navicat的快捷鍵:
Ctrl+Q、Ctrl+N 打開查詢窗口
Ctrl+/ 注釋sql語句
Ctrl+Shift +/ 解除注釋
Ctrl+R 運(yùn)行查詢窗口的sql語句
F6 打開一個(gè)mysql命令行窗口
Ctrl+L 刪除一行
Ctrl+W 關(guān)閉一個(gè)查詢窗口
Ctrl+D 表的數(shù)據(jù)顯示顯示頁面切換到表的結(jié)構(gòu)設(shè)計(jì)頁面,但是在查詢頁面寫sql時(shí)是復(fù)制當(dāng)前行
和權(quán)限有關(guān)的幾張表
大家覺得mysql數(shù)據(jù)庫基本授權(quán)的具體操作流程這篇文章怎么樣,是否有所收獲。如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。