rpm方式安装
1.卸载之前安装的
查询下本机mysql是否卸载干净
若有残留也需要卸载
由于centOS7中默认安装了MariaDB,也需要先进行卸载
//查询命令
rpm -qa | grep -i mysql或者 MariaDB
//删除命令
rpm -e --nodeps 文件名
//强制删除命令
rpm -e --noscripts 文件名
2.下载MySQL
https://downloads.mysql.com/archives/community/
选择需要的版本下载
上传至服务器 自建文件夹
解压安装包
mkdir /usr/local/MySQL
tar -zxvf mysql-5.7.40-1.el7.x86_64.rpm-bundle.tar
解压完:
3. 顺序安装解压的安装吧
rpm -ivh mysql-community-common-5.7.40-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.40-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.40-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.40-1.el7.x86_64.rpm
yun install net-tools
rpm -ivh mysql-community-server-5.7.40-1.el7.x86_64.rpm
4 . 启动MySQL
//启动MySQL服务
systemctl start mysqld
//重启MySQL
systemctl restart mysqld
//查看MySQL服务状态
systemctl status mysqld
//停止MySQL服务
systemctl stop mysqld
查看服务是否启动成功
ps –ef | grep mysql
5. 登录MySQL
查看临时密码
cat /var/log/mysqld.log | grep password
临时密码登录MySQL
6. 修改密码
修改设置
//设置密码长度最低位数
set global validate_password_length=4;
//设置密码安全等级低
set global validate_password_policy=LOW;
//修改秘密为root
set password = password('root');
修改权限
//开启访问权限
grant all on *.* to 'root'@'%' identified by 'root';
//刷新
flush privileges;
7. 成功连接MySQL
8. 注意!!!
修改数据库的编码
MySQL默认编码为latin1,需要修改为UTF8
//查询现在的编码
show global variables like "%char%";
编辑 /etc/my.cnf文件
vim /etc/my.cnf
//[client]下增加
default_character_set=utf8
//[mysql]下增加
default_character_set=utf8
//[mysqld]下增加
character_set_server=utf8
//修改完后,重启MySQL
systemctl restart mysqld