遠程登錄mysql
mysql -h ip -u root -p 密碼
創建用戶
格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by “密碼”;
例1:增加一個test1用戶,密碼為123456,需要在mysql的root用戶下進行
可以在任何主機上登錄,并對所有數據庫有查詢,增加,修改和刪除的功能。
grant select,insert,update,delete on *.* to test1@"%" identified by "123456";
flush privileges;
例2:增加一個test2用戶,密碼為123456,只能在192.168.2.12上登錄,
并對數據庫student有查詢,增加,修改和刪除的功能。需要在mysql的root用戶下進行
grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by "123456";
flush privileges;
例3:授權用戶test3擁有數據庫student的所有權限
grant all privileges on student.* to test3@localhost identified by '123456';
flush privileges;
修改用戶密碼
update mysql.user set password=password('123456') where User='test1' and Host='localhost';
flush privileges;
刪除用戶
delete from user where user='test2' and host='localhost';
flush privileges;
刪除數據庫和刪除表
drop database 數據庫名;
drop table 表名;
刪除賬戶及權限
drop user 用戶名@'%'
drop user 用戶名@localhost