安装wget:
yum -y install wget
进入/usr/local/下:
cd /usr/local/
新建mysqlrpm文件夹:
mkdir mysqlrpm
进入mysqlrpm文件夹下:
cd /usr/local/mysqlrpm/
下载mysql包安装源:
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查Mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
更新获取新的密钥(如果密钥失败再搜)
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
安装mysql:
yum install mysql-community-server
安装完成后启动mysql服务:
systemctl start mysqld
查看mysql状态:
systemctl status mysqld
安装时系统会创建一个root密码 需要获取到root密码
grep 'temporary password' /var/log/mysqld.log
密码:
Cnmtespj9m;&
显示密码后登陆mysql客户端:
mysql -u root -p
进入mysql客户端后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL5.7#';
允许mysql被远程登录访问设置
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MySQL5.7#' WITH GRANT OPTION;
设置MySQL字符编码格式
vim /etc/my.cnf
在[mysqld]下加入以下内容
character_set_server=utf8
init_connect='SET NAMES utf8'
lower_case_table_names=1
因为windows系统是大小写不敏感 Linux是严格区分大小写的
加入完成后保存退出 重启mysql服务:systemctl restart mysqld
重启完成后进入mysql 通过下面命令查看编码设置:
show variables like '%character%';
mysql环境变量查询当前mysql密码策略相关信息:
show variables like '%password%';
# 配置文件
/etc/my.cnf
# 日志文件
/var/log/var/log/mysqld.log
# 服务启动脚本
/usr/lib/systemd/system/mysqld.service
# socket文件
/var/run/mysqld/mysqld.pid