背景
本次安装是在centos7上安装mysql-5.7.29
下载安装包
下载mysql 5.7
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
解压安装包
解压安装包并安装
tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
安装新版mysql前,需将系统自带的mariadb-lib卸载(mariadb-libs-5.5.60-1.el7_5.x86_64)
#查看
rpm -qa|grep mariadb
#卸载
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
为了避免出现权限问题,给mysql解压文件所在目录赋予最大权限
chmod -R 777 mysql
严格按照顺序安装:
mysql-community-common-5.7.29-1.el7.x86_64.rpm
、
mysql-community-libs-5.7.29-1.el7.x86_64.rpm
、
mysql-community-client-5.7.29-1.el7.x86_64.rpm
、
mysql-community-server-5.7.29-1.el7.x86_64.rpm
这四个包
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm
如果安装过程中出现这个错误就在后面添加 --force --nodeps,这可能是由于yum安装了旧版本的GPG keys造成的
启动mysql
配置数据库
vim /etc/my.cnf
添加这三行
skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'
skip-grant-tables:跳过登录验证
character_set_server=utf8:设置默认字符集UTF-8
init_connect=‘SET NAMES utf8’:设置默认字符集UTF-8
顺便添加下binlog配置
server-id=1
log-bin=mysql-bin
binlog_format=ROW
查看binlog生效与否
show variables like 'log_bin';
启动mysql
systemctl start mysqld.service
进入mysql客户端
mysql
设置简单用户和密码
update mysql.user set authentication_string=password('123456') where user='root’;
刷新账户密码,使之生效,并退出mysql客户端
flush privileges;
关闭mysql服务
systemctl stop mysqld.service
编辑my.cnf配置文件将:skip-grant-tables
这一行注释掉
重启mysql服务
systemctl start mysqld.service
登录mysql客户端
mysql -uroot -p123456
修改root密码
set password=password('123456');
如果一直报这个错误
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user user() identified by "rootM123456_*(;";
查看密码策略
SHOW VARIABLES LIKE 'validate_password%’;
1)、validate_password_length 固定密码的总长度;
2)、validate_password_dictionary_file 指定密码验证的文件路径;
3)、validate_password_mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
4)、validate_password_number_count 整个密码中至少要包含阿拉伯数字的个数;
5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
设置密码的验证强度等级,设置 validate_password_policy 的全局参数为 LOW
set global validate_password_policy=LOW;
只要设置密码的长度小于 3 ,都将自动设值为 4
set global validate_password_length=4;
这样就可以修改成简单密码了
set password=password('123456');
开放端口
开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp —permanent
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd —reload
开启远程登录
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
可以设置一个别的密码给远程登录使用
开机自启动
systemctl enable mysqld.service
docker下安装mysql5.7 并开启binlog
下载并安装mysql5.7
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
清理无用的镜像和容器
docker system prune -a
本地创建目录
mkdir -p /etc/mysql/conf/mysql/mysql.conf.d
将配置文件拷贝到本地目录
docker cp mysql:/etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/conf/mysql/mysql.conf.d
修改配置文件
vi /etc/mysql/conf/mysql/mysql.conf.d/mysqld.cnf
# 将下面的配置追加进去
server-id=1
log-bin=mysql-bin
binlog_format=ROW
将配置重新放入docker容器
docker cp /etc/mysql/conf/mysql/mysql.conf.d/mysqld.cnf mysql:/etc/mysql/mysql.conf.d/mysqld.cnf
重启容器
docker restart mysql
参考资料
https://www.cnblogs.com/lzhdonald/p/12511998.html