标签:mysql用户 sql语句 mysql备份 mysql恢复
MySQL用户管理grant all on *.* to ‘user1‘@‘localhost‘ identified by ‘123456‘;
grant all on db1.* to ‘user2‘@‘%‘ identified by ‘123456‘; //创建user2用户,所有ip都能登录,指定权限为db1库下的所有表;
flush privileges;
刷新授权
.:表示所有库和表;
user1:用户名;
localhost:登录ip,默认localhost为本机登录ip,也可以使用%代表所有;
show grants;
show grants for ‘user1‘@‘%‘; //查询用户user1,限制ip为所有的权限;
select:查看;
insert:插入;
update:更改;
drop:删除;
select count(*) from mysql.user; //count()表示统计行数;*代表所有;
+----------+
| count(*) |
+----------+
| 9 |
+----------+
1 row in set (0.01 sec)
select * from mysql.db; //查看mysql库下db表的所有内容;
select db from mysql.db; //查找mysql库下db表里面db列的内容;
select db,user from mysql.db; //查找mysql库下db表中db列与user列的内容;
select * from mysql.db where host like ‘192.168.%‘; //查找mysql.db下带有192.168.字样的列出来
insert into db1.t1 values (1,‘abc‘); //在db1.t1中,插入两条数据,第一条为数字1,第二条为字符串abc;
mysql>select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
+------+------+
1 row in set (0.00 sec)
update db1.t1 set name=‘aaa‘ where id=1; //将db1.t1的id为1的 name内容更改为字符串aaa
mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | aaa |
| 2 | 123 |
+------+------+
2 rows in set (0.00 sec)
truncate table db1.t1;
truncate table db1.t1; //将db1.t1表的内容全部清空掉;
select * from db1.t1; //查询db1.t1的内容
Empty set (0.00 sec)
drop table db1.t1; //删除t1表
drop database db1; //删除数据库db1
mysqldump -uroot -p‘123456‘ mysql > /tmp/backup/mysqlbak.sql //将名为mysql的数据库备份到指定目录下
mysql -uroot -p‘123456‘ mysql < /tmp/backup/mysqlbak.sql //将指定目录下的备份文件恢复为mysql数据库
mysqldump -uroot -p‘123456‘ mysql user >/tmp/backup/user.sql //将mysql下的user表备份到指定目录
mysql -uroot -p‘123456‘ mysql < /tmp/backup/user.sql //将指定目录下的表恢复到mysql库下
mysqldump -uroot -p‘123456‘ -A > /tmp/backup/123.sql //将所有数据库备份到指定目录
mysqldump -uroot -p‘123456‘ -d mysql > /tmp/backup/mysql-biaojg.sql
标签:mysql用户 sql语句 mysql备份 mysql恢复
原文地址:http://blog.51cto.com/shuzonglu/2090543