Linux运维必会的100道MySql面试题之一

3次阅读

共计 1726 个字符,预计需要花费 5 分钟才能阅读完成。

接上一篇:Mysql 数据库基础操作命令

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 test\G


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

点击关注 民工哥技术之路 微信公众号对话框回复关键字:1024 可以获取一份最新整理的技术干货:包括系统运维、数据库、redis、MogoDB、电子书、Java 基础课程、Java 实战项目、架构师综合教程、架构师实战项目、大数据、Docker 容器、ELK Stack、机器学习、BAT 面试精讲视频等。

正文完
 0