MYSQL2
13.4 MySQL用户管理
13.5 常用sql语句
13.6 MySQL数据库备份恢复
13.4 MySQL用户管理
1,创建用户,
mysql> grant all on *.* to 'user1'@'127.0.0.1' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
解释说明:*.*代表所有的表,127.0.0.1代表允许的ip
登录尝试,这里需要加-h127.0.0.1才能登陆
2,既然如此,我们授权一下user1(grand密码不安全,是不会记录到日志的)
mysql> show grants for [email protected]'127.0.0.1';
授权localhost
mysql> grant all on *.* to 'user1'@'localhost' identified by '123456';
再次尝试,这样的话,就OK了,不需要加-h,localhost就是针对的localhost
3,show grants查看授权
mysql> show grants for [email protected]'localhost';也可以指定对应的user,例如下面查看user1的
创建一个user2的用户
mysql> grant all on *.* to 'user2'@'192.168.188.2' identified by '123456';
show grants for [email protected]'192.168.188.2'; //注意加;号代表语句结束
-
- 常用sql语句
1,我们先切换到db1下,
use db1
select count(*) from mysql.user; //查询mysql库中user表的行数
select * from mysql.db; //查询所有的内容,用*号会很消耗资源
一般用mysisam innodb
Mysisam 可以自动统计多少行
Innodb则不会统计行数
select db from mysql.db; // db一个字段,搜索字段命令
也可以有两个字段,例如db.user
依据类型查看select * from mysql.db where host like '192.168.%'\G;
select * from db1.t1; //查看是空的
Empty set (0.00 sec)
插入一个
insert into db1.t1 values (1, 'abc'); .//插入abc的表
在查看,则创建了一个abc的表了
如果增加一个字符串
这里出入最好加入一个单引号
update db1.t1 set name='aaa' where id=1; //将id为1的设置成aaa
update db1.t1 set name='aaa' where id=1; //将id=1的设置成name为aaa
delete from db1.t1 where id=1; //删除id为1的表组
删除表操作,也可以用truncate
Truncate 还留着壳子
drop则是壳都删除了,这里不再演示,一定要谨慎操作
13.6 MySQL数据库备份恢复
备份库
mysqldump -uroot -p123456 mysql > /tmp/mysqlbak.sql //备份库到mysqlbak.q
创建myslq2库
[[email protected] ~]# mysql -uroot -p123456 -e "create database mysql2"
Warning: Using a password on the command line interface can be insecure.
恢复库
[[email protected] ~]# mysql -uroot -p123456 mysql2 < /tmp/mysqlbak.sql
Warning: Using a password on the command line interface can be insecure.
备份表
[[email protected] ~]# mysqldump -uroot -p123456 mysql user > /tmp/user.sql
[[email protected] ~]# less /tmp/user.sql
恢复表(备份用mysqldump,恢复用mysql)
mysqldump -uroot -p123456 mysql2 </tmp/user.sql
[[email protected] ~]# mysqldump -uroot -p123456 -A >/tmp/mysql_all.sql //-A代表所有的库
扩展
mysql5.7 root密码更改 http://www.apelearn.com/bbs/thread-7289-1-1.html
myisam 和innodb引擎对比 http://www.pureweber.com/article/myisam-vs-innodb/
mysql 配置详解: http://blog.linuxeye.com/379.html
mysql调优: http://www.aminglinux.com/bbs/thread-5758-1-1.html
亲身mysql调优经历: http://www.apelearn.com/bbs/thread-11281-1-1.html
SQL语句教程 http://www.runoob.com/sql/sql-tutorial.html
什么是事务?事务的特性有哪些? http://blog.****.net/yenange/article/details/7556094
根据binlog恢复指定时间段的数据 https://blog.****.net/lilongsy/article/details/74726002
mysql字符集调整 http://xjsunjie.blog.51cto.com/999372/1355013