MySQL安装
MySql安装
1、下载mysql安装包
再mysql官方下载安装包
2、删除依赖包
# 查找依赖包
rpm -qa | grep mysql
rpm -qa | grep MySQL
rpm -qa | grep mariadb
# 删除查询到的依赖包
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
3、安装mysql
# 将安装包上传到linux中
# mysql-community-client-5.7.37-1.el7.x86_64.rpm
# mysql-community-common-5.7.37-1.el7.x86_64.rpm
# mysql-community-libs-5.7.37-1.el7.x86_64.rpm
# mysql-community-server-5.7.37-1.el7.x86_64.rpm
# 安装mysql
rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
# 如果安装过程中出现缺少依赖,将依赖安装以下
# yum -y install autoconf
# yum -y install net-tools
4、启动mysql
systemctl start mysqld
# 插入状态
systemctl status mysqld
5、修改mysql登录密码
# 获取临时密码
grep 'temporary password' /var/log/mysqld.log
# 通过临时密码登录mysql
mysql -uroot -p
# 修改密码的安全策略
set global validate_password_policy=0;
set global validate_password_length=4;
# 修改密码
set password = password('123456');
# 刷新权限
flush privileges;
# 退出
exit
7、使用
-- 1、登录数据库
mysql -uroot -p123456
-- 2、创建数据库 -- DDL
create database bigdata default charset utf8;
-- 3、列出所有的数据库
show databases;
-- 4、切换数据库
use bigdata;
-- 5、创建表 -- DDL
create table students(
id varchar(255),
name varchar(255),
age int,
sex varchar(255),
clazz varchar(255)
);
-- 6、使用sql导入数据到表中
LOAD DATA local INFILE '/root/student.txt' INTO TABLE students FIELDS TERMINATED BY ',' ;
--7、使用sql查询数据
-- 1、查询文科一班的学生
select * from students where name='范念薇';
-- 2、统计每个班级的人数
select
clazz,count(1) as num
from students
group by clazz;
Mysql卸载
1、停止mysql服务
systemctl stop mysqld
2、删除依赖包
rpm -qa |grep -i mysql
yum remove mysql-community mysql-community-server mysql-community-libs mysql-community-common
3、删除mysql文件
# 查找和mysql相关的所有的文件
find / -name mysql
# 删除以下目录
/etc/logrotate.d/mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql # mysql保存数据的位置
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/mysql