mysql的九个常用语句_2018.9.27日,预习笔记,MySQL常用操作

笔记目录:

设置更改root密码

连接mysql

mysql常用命令

mysql用户管理

常用sql语句

mysql数据库备份恢复

扩展:使用xtrabackup备份innodb引擎的数据库 innobackupex 备份 Xtrabackup 增量备份 http://zhangguangzhi.top/2017/08/23/innobackex%E5%B7%A5%E5%85%B7%E5%A4%87%E4%BB%BDmysql%E6%95%B0%E6%8D%AE/#%E4%B8%89%E3%80%81%E5%BC%80%E5%A7%8B%E6%81%A2%E5%A4%8Dmysql

相关视频

链接:http://pan.baidu.com/s/1miFpS9M 密码:86dx

链接:http://pan.baidu.com/s/1o7GXBBW 密码:ue2f

扩展

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.csdn.net/yenange/article/details/7556094

根据binlog恢复指定时间段的数据 https://blog.csdn.net/lilongsy/article/details/74726002

mysql字符集调整 http://xjsunjie.blog.51cto.com/999372/1355013

https://www.cnblogs.com/aguncn/p/4313724.html

https://www.zhihu.com/question/20596402

https://blog.csdn.net/lilongsy/article/details/74726002

https://note.youdao.com/share/?token=70F9416173B94FDCBE1E6B3D2A9CF271&gid=31981530#/

一.设置更改root密码

45770c001f956ea601fdbe0295f9e5df.png

示例一:

/usr/local/mysql/bin/mysql -uroot

更改环境变量PATH,增加mysql绝对路径

export PARH=$PATH:/usr/local/mysql/bin/

vi /etc/profile 将这个变量添加到里面去,可以永久生效

source /etc/profile 即可生效

mysql -uroot -p 进入mysql 命令行

eec1dbb47367726a441de542d33d8414.png

mysqladmin -uroot password '123456'  设置mysql密码

mysql -uroot -p123456

示例一:密码重置

vi /etc/my.cnf//增加skip-grant  乎滤授权

b228ef9ce7a24987ab4ae1d159f47a45.png

重启mysql服务 /etc/init.d/mysqld restart

mysql -uroot  进入mysql命令行

use mysql;  切换库

update user set password=password('aminglinux') where user='root';

quit 退出

/etc/init.d/mysqld restart 重启mysql

mysql -uroot -p 使用新密码就可以登录到mysql命令行了

二.连接mysql

42bc4652f35a9e5dc6a2d5a63c714802.png

示例一:

mysql -uroot -p123456  默认使用socket连接的

mysql -uroot -p123456 -h127.0.0.1 -P3306  大P是指定端口号,使用端口连接

mysql -uroot -p123456 -S/tmp/mysql.sock  大S是指定socket,只适合在本机连接

80929595ca63367371910117c8ccaaf7.png

mysql -uroot -p123456 -e “show databases”  连接mysql通知操作一些命令,用-e指定命令,一般用来使用在shell脚本里面

三.mysql常用命令

7ad1602082d44f06950183cab60ac27b.png

ae7f8e8a3e868724e0c3882fc69b885b.png

示例一:

查询库 show databases;

切换库 use mysql;

查看库里的表 show tables;

查看表里的字段 desc tb_name;

查看建表语句 show create table tb_name\G;

查看当前用户 select user();

查看当前使用的数据库 select databsase();

创建库 create database db1;

创建表 use db1; create table t1(`id` int(4), `name` char(40));

删除表 jrop table;

查看当前数据库版本 select version();

查看数据库状态 show status;

查看各参数 show variables; show variables like 'max_connect%';

修改参数 set global max_connect_errors=1000;  在内存中生效

永久生效,vim /etc/my.cnf 在这里定义参数,就能重启还生效了

查看队列 show processlist;

show full processlist;会显示的更全

四.mysql用户管理

6310d6d7187b4f6898a105997ac1b632.png

示例一:

grant all on *.* to 'user1' @‘127.0.0.1‘ identified by 'passwd';  创建用户并指定来源IP。

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 user2@192.168.133.1; 查看指定用户的授权,用来复制一个用户的时候会用上

五.常用sql语句

8986a71f2122cc73de475197914a61fc.png

示例一:

select count(*) from mysql.user;   查看这个表的行数

0524850b63f59f70d1cdd1abd4aff399.png

select * from mysql.db;  select db from mysql.db; 查看所有的内容

select db,user from mysql.db;  查看字段

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

insert into db1.t1 values (1, 'abc');  插入一条数据

update db1.t1 set name='aaa' where id=1;  更改表数据

truncate table db1.t1;  清空一个表

drop table db1.t1;  删除表

drop database db1; 删除数据库

六.mysql数据库备份恢复

9bf0ba12ff382bb074bd546d7b7956df.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

七.扩展:使用xtrabackup备份innodb引擎的数据库 innobackupex 备份 Xtrabackup 增量备份 http://zhangguangzhi.top/2017/08/23/innobackex%E5%B7%A5%E5%85%B7%E5%A4%87%E4%BB%BDmysql%E6%95%B0%E6%8D%AE/#%E4%B8%89%E3%80%81%E5%BC%80%E5%A7%8B%E6%81%A2%E5%A4%8Dmysql

相关视频

链接:http://pan.baidu.com/s/1miFpS9M 密码:86dx

链接:http://pan.baidu.com/s/1o7GXBBW 密码:ue2f

扩展

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.csdn.net/yenange/article/details/7556094

根据binlog恢复指定时间段的数据 https://blog.csdn.net/lilongsy/article/details/74726002

mysql字符集调整 http://xjsunjie.blog.51cto.com/999372/1355013

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值