MySQL5.7
CHARACTER SET utf8 COLLATE utf8_general_ci
use mysql;
CREATE USER 'reader'@'%' IDENTIFIED BY '123456';
grant all privileges on mall.* to 'reader'@'%';
flush privileges;
進(jìn)入mysql
切換到use表
更新host為%
執(zhí)行修改
mysql -uroot -p
psaaword:
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
grant all privileges on guoya_vitual_mall.* to 'test'@'%' identified by '123456..';
grant all privileges on guoya_vitual_mall.* to 'test1'@'%' identified by '123456';
安裝MySQL
sudo mysql -u root #使用root用戶權(quán)限登錄mysql
SELECT User,Host FROM mysql.user; #查看用戶與host信息
+------------------+-----------+
| User | Host |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
DROP USER 'root'@'localhost'; #刪除root賬號
Query OK, 0 rows affected (0.00 sec)
CREATE USER 'root'@'%' IDENTIFIED BY '****'; #添加root賬戶并設(shè)置登錄密碼,'****'符號內(nèi)為密碼
Query OK, 0 rows affected (0.00 sec)
4.為root用戶授權(quán)剩燥,使其具有可以創(chuàng)建修改數(shù)據(jù)庫等的權(quán)限
GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
CREATE USER 'test'@'%' IDENTIFIED BY '123456..';
create database guoya_teach_test;
FLUSH PRIVILEGES; #重新加載權(quán)限
Query OK, 0 rows affected (0.00 sec)
為用戶授權(quán)
授權(quán)格式:grant 權(quán)限 on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by "密碼";
2.1 登錄MYSQL(有ROOT權(quán)限)模聋,這里以ROOT身份登錄:
@>mysql -u root -p
@>密碼
2.2 首先為用戶創(chuàng)建一個數(shù)據(jù)庫(testDB):
mysql>create database testDB;
2.3 授權(quán)test用戶擁有testDB數(shù)據(jù)庫的所有權(quán)限(某個數(shù)據(jù)庫的所有權(quán)限):
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';
mysql>flush privileges;//刷新系統(tǒng)權(quán)限表
格式:grant 權(quán)限 on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by "密碼";
2.4 如果想指定部分權(quán)限給一用戶韭畸,可以這樣來寫:
mysql>grant select,update on testDB.* to test@localhost identified by '1234';
mysql>flush privileges; //刷新系統(tǒng)權(quán)限表
2.5 授權(quán)test用戶擁有所有數(shù)據(jù)庫的某些權(quán)限:
mysql>grant select,delete,update,create,drop on . to test@"%" identified by "1234";
//test用戶對所有數(shù)據(jù)庫都有select,delete,update,create,drop 權(quán)限悔叽。
//@"%" 表示對所有非本地主機授權(quán)饼齿,不包括localhost拳话。(localhost地址設(shè)為127.0.0.1漫仆,如果設(shè)為真實的本地地址泊碑,不知道是否可以坤按,沒有驗證。)
//對localhost授權(quán):加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可馒过。