MySQL常用操作(下)
用戶管理
mysql> grant all on *.* to [email protected] identified by ‘123456‘; ##創建用戶並授權 mysql> grant SELECT,UPDATE,INSERT on db1.* to [email protected] identified by ‘passwd‘; mysql> grant all on db1.* to [email protected]%‘ identified by ‘passwd‘; mysql> show grants; ##查看授權 mysql> show grants for [email protected]
常用語句
mysql> select count(*) from mysql.user; ##查看庫mysql的表user mysql> select * from mysql.db\G; ##查看表內所有內容 mysql> select db from mysql.db; ##查看db表裏的db mysql> select db,user from mysql.db; ##查看db表裏的db和user mysql> select * from mysql.db where host like ‘127.0.0.%‘; ##模糊查詢 mysql> insert into db1.t1 values (1, ‘abc‘); ##向表內插入數據 mysql> update db1.t1 set name=‘aaa‘ where id=1; ##更改表內數據 mysql> truncate table db1.t1; ##清空表 mysql> drop table db1.t1; ##刪除表 mysql> drop database db1; ##刪除庫
備份與恢復
[[email protected] ~]# mysqldump -uroot -p88888888 mysql > /tmp/mysql.sql ##備份庫 [[email protected] ~]# mysql -uroot -p88888888 mysql < /tmp/mysql.sql ##恢復庫 [[email protected] ~]# mysqldump -uroot -p88888888 mysql user > /tmp/user.sql ##備份表 [[email protected]