2018-6-20

13.4 mysql用戶管理

13.5 常用sql語句

13.6 mysql數據庫備份恢復




13.4 mysql用戶管理

主要是設置用戶對哪個的權限

grant all on *.* to 'user1'@'127.0.0.1' identified by '123456a';  //grant all 授權操作,這個用戶只能通過127來登陸

image.png

mysql -uuser1 -p123456a -h127.0.0.1

image.png

測試成功,已連上


修改grant all on *.* to 'user1'@'127.0.0.1' identified by '123456a';  變爲

 grant all on *.* to 'user1'@'localhost' identified by '123456a'; 

image.png

這樣登陸的時候無需添加 -h



grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'192.168.133.1' identified by 'passwd'; //針對具體的權限去修改

grant all on db1.* to 'user3'@'%' identified by 'passwd'; //針對所有ip授權

show grants; //查看授權

show grants for [email protected]; //查看指定用戶授權










13.5 常用sql語句

 select count(*) from mysql.user; //查找這個表的行數

image.png

select * from mysql.db; //查看所有內容,可以價格\G用豎排顯示看的比較直觀

image.png

 select db from mysql.db; //查找字段

select db,user from mysql.db;

 select * from mysql.db where host like '192.168.%';  // like  模糊匹配

 insert into db1.t1 values (1, 'abc');  //插入字符串

 update db1.t1 set name='aaa' where id=1; //將id=1的名字更改爲aaa

 truncate table db1.t1; //清空表裏的內容

 drop table db1.t1; //不僅清空表裏的內容並且連框架也去掉

 drop database db1;








13.6 mysql數據庫備份恢復

mysqldump是備份的命令

image.png

屏幕上輸出的都是數據庫裏的內容

備份庫  mysqldump -uroot -p123456 mysql > /tmp/mysql.sql //重定向到文件裏,就成了備份文件

 恢復庫 mysql -uroot -p123456 mysql < /tmp/mysql.sql

 備份表 mysqldump -uroot -p123456 mysql user > /tmp/user.sql

 恢復表 mysql -uroot -p123456 mysql < /tmp/user.sql

 備份所有庫 mysqldump -uroot -p -A >/tmp/123.sql

 只備份表結構 mysqldump -uroot -p123456 -d mysql > /tmp/mysql.sql


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章