Linux MySQL安装教程
准备工作
关闭防火墙修改主机名配置静态IP CentOS换源
1. 备份2. 下载新的 CentOS-base.repo 到 /etc/yum.repos.d/3. 运行 yum makecache 生成缓存4. 其他 安装mysql5.7
下载yum Repository安装yum Repository安装mysql5.7 m'y开机自启动启动mysql查看状态获取临时密码登录mysql关闭密码复杂验证设置密码切换数据库修改权限
开放root用户远程登录刷新权限查看权限修改MySQL编码 其它操作
卸载yum Repository 卸载mysql
删除依赖包清理文件
Linux MySQL安装教程 准备工作 关闭防火墙# 停止firewall systemctl stop firewalld.service # 禁止firewall开机启动 systemctl disable firewalld.service # 查看防火墙状态 systemctl status firewalld.service修改主机名
vim /etc/hostname # 查看主机名 hostname配置静态IP
# 停止NetworkManager服务 systemctl stop NetworkManager # 取消NetworkManager服务开机自启 systemctl disable NetworkManager # 修改配置文件,配置静态IP cd /etc/sysconfig/network-scripts vim ifcfg-ens33 # 以下配置仅供参考!!!需要根据自己的实际情况配置 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes NAME=ens33 DEVICE=ens33 onBOOT=yes IPADDR=192.168.190.100 NETMASK=255.255.255.0 GATEWAY=192.168.190.2 DNS1=192.168.190.2 # 重启网络服务 systemctl restart networkCentOS换源 1. 备份
mv /etc/yum.repos.d/CentOS-base.repo /etc/yum.repos.d/CentOS-base.repo.backup2. 下载新的 CentOS-base.repo 到 /etc/yum.repos.d/
CentOS 6
curl -o /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 8
wget -O /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
或者
curl -o /etc/yum.repos.d/CentOS-base.repo https://mirrors.aliyun.com/repo/Centos-8.repo3. 运行 yum makecache 生成缓存 4. 其他
非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置: eg:
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-base.repo
安装mysql5.7
按照下面顺序依次复制粘贴即可
下载yum Repositorywget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm安装yum Repository
yum -y install mysql57-community-release-el7-10.noarch.rpm安装mysql5.7 m’y
yum -y install mysql-community-server开机自启动
systemctl enable mysqld.service启动mysql
systemctl start mysqld.service查看状态
systemctl status mysqld.service获取临时密码
grep "password" /var/log/mysqld.log
把获取的临时密码拷贝一下
登录mysqlmysql -uroot -p [粘贴上刚刚获取的临时密码]关闭密码复杂验证
set global validate_password_policy=0; set global validate_password_length=1;设置密码
alter user user() identified by "123456";切换数据库
use mysql;修改权限 开放root用户远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;刷新权限
flush privileges;查看权限
select host,user,authentication_string from user;修改MySQL编码
编辑配置文件:vim /etc/my.cnf
[client] default-character-set = utf8mb4 [mysqld] character-set-server = utf8mb4 collation-server = utf8mb4_general_ci
重启MySQL
systemctl restart mysqld
登录并查看MySQL编码
# 123456需替换为自己的密码 mysql -uroot -p123456 # 需在MySQL的shell中执行 show variables like "%char%";
其它操作 卸载yum Repository
因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉
yum -y remove mysql57-community-release-el7-10.noarch卸载mysql 删除依赖包
rpm -qa |grep -i mysql yum remove mysql-community mysql-community-server mysql-community-libs mysql-community-common清理文件
find / -name mysql rm -rf [文件名]
到底啦!给靓仔一个关注吧!



