//允許本地訪問
create user 'username'@'localhost' identified by 'password';
// 允許外網(wǎng)訪問
create user 'username'@'%' identified by 'password';
//刷新授權(quán)
flush privileges;
修改密碼
8.0.4以前修改密碼
SET PASSWORD=PASSWORD('修改的密碼');
8.0.4以后修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY
'newpasswd';
ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpasswd';
//外網(wǎng)
ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY
'newpasswd';
// mysql_native_password 表示傳統(tǒng)的加密方式(mysql 5.x),不使用該選項則使用新的加密方式(mysql 8)
分配權(quán)限
# create database testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
//# grant all privileges on testdb.* to 'username'@'localhost' (identified with mysql_native_password by 'password'; )
// 不需要更改密碼蕉饼,括號內(nèi)的可不寫
# grant all privileges on testdb.* to 'username'@'%' ( identified with mysql_native_password by 'password'; )
// *.*所有數(shù)據(jù)庫监憎; tested.*表示只能操作testdb數(shù)據(jù)庫; testedb.student表示只能操作testdb數(shù)據(jù)庫的student表;
// 分配部分權(quán)限: insert, select,update,delete,create,drop,alter(為表增刪改字段add,delete,modify/change),
//刷新權(quán)限
# flush privileges