写此文章的由来,源于老男孩老师在群里发的一篇文章
** “Linux运维班MySQL必会面试题100道”**
因此,民工哥将题抄录下来,然后在线下环境将答案逐一验证,并写出来分享给需要的小伙伴,因答案纯属个人观点,难免会有不正之处,还望小伙伴加改指正
01
如何启动MySql服务
/etc/init.d/mysqld start
service mysqld start
Centos 7.x 系统
sysctl start mysqld
02
检测端口是否运行
lsof -i :3306
netstat -lntup |grep 3306

03
设置或修改MySql密码
设置密码
mysql -uroot -ppassword -e “set passowrd for root = passowrd(‘passowrd’)”
mysqladmin -uroot passowrd “NEWPASSWORD”
更改密码
mysqladmin -uroot passowrd oldpassowrd “NEWPASSWORD”
use mysql;
update user set passowrd = PASSWORD(‘newpassword’) where user = ‘root’;flush privileges;
**msyql 5.7以上版本修改默认密码命令 **
alter user ‘root‘@’localhost’ identified by ‘root’
04
登陆数据库
mysql -uroot -ppassword
05
查看当前数据库的字符集
show create database DB_NAME;
06
查看当前数据库版本
mysql -V
mysql -uroot -ppassowrd -e “use mysql;select version();”

07
查看当前登录用户
mysql -uroot -ppassowrd -e “select user();”

select user(); #进入数据库查询
08
创建GBK字符集数据库mingongge并查看完整创建语句
create database mingongge default charset gbk collate gbk_chinese_ci;
09
创建用户mingongge使用之可以管理数据库mingongge
grant all on mingongge.* to ‘mingongge‘@’localhost’ identified by ‘mingongge’;
10
查看创建用户mingongge的权限
show grants for mingongge@localhost;

11
查看当前数据库有哪此用户
select user from mysql.user;
12
进入mingongge数据库
use mingongge

13
创建一个innodb GBK表test,字段id int(4)和name varchar(16)
create table test (
id int(4),
name varchar(16)
)ENGINE=innodb DEFAULT CHARSET=gbk;
14
查看建表结构及表结构的SQL语句
desc test;
show create table testG

15
插入一条数据“1,mingongge”
insert into test values(‘1’,’mingongge’);
16
再批量插入2行数据“2,民工哥”,“3,mingonggeedu”
insert into test values(‘2’,’民工哥’),(‘3’,’mingonggeedu’);
17
查询名字为mingongge的记录
select * from test where name = ‘mingongge’;

18
把数据id等于1的名字mingongge更改为mgg
update test set name = ‘mgg’ where id = ‘1’;
19
在字段name前插入age字段,类型tinyint(2)
alter table test add age tinyint(2) after id;

20
不退出数据库,完成备份mingongge数据库
system mysqldump -uroot -ppassword -B mingongge /root/mingongge_bak.sql




如有帮助,扫码即刻打赏民工哥吧!!!
