==基于RPM的Mysql安装==
登录网易开源镜像站下载RPM安装包
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
解压
tar -xvf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
查看当前系统是否已安装,并卸载已安装的mysql版本
rpm -qa | grep mysql
安装
rpm -qa | grep -i mysql
卸载
rpm -e rpm包名
按顺序安装以下rpm包
rpm -hiv mysql-community-common-5.7.30-1.el6.x86_64.rpm
rpm -hiv mysql-community-libs-5.7.30-1.el6.x86_64.rpm
rpm -hiv mysql-community-client-5.7.30-1.el6.x86_64.rpm
rpm -hiv mysql-community-server-5.7.30-1.el6.x86_64.rpm
获取临时密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2021-01-03T23:03:04.193661Z 1 [Note] A temporary password is generated for root@localhost: rO2%HtK/AcL=
登录mysql
mysql -uroot -p
修改默认密码规则_修改密码
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> set global validate_password_policy=LOW;
mysql> set global validate_password_length=5;
mysql> set password for 'root'@'localhost'=password('xiaojiandnf');
#授权远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xiaojiandnf' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
开机自动启动
chkconfig mysqld on
[toc]
==基于Docker安装mysql==
创建外部挂载的目录
mkdir -p /docker/mysql/conf
mkdir -p /docker/mysql/logs
mkdir -p /docker/mysql/data
创建==my.cnf==配置文件
touch /docker/mysql/conf/my.cnf
复制以下内容
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections = 2000
max_user_connections = 1900
max_connect_errors = 100000
max_allowed_packet = 50M
lower_case_table_names=1
[mysqld]
skip-name-resolve
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#开启binlog
log-bin=mysql-bin
binlog_format=ROW
server_id=1
运行docker容器
[root@localhost ~]# docker run -p 3306:3306 --name mysql -v /docker/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /docker/mysql/logs:/logs -v /docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=xiaojiandnf -d mysql:5.7
参数详解:
-p 3306:3306 \ #映射端口
> --name mysql \ #容器名称
> -v /docker/mysql/conf/my.cnf:/etc/mysql/my.cnf \ #挂载本地配置文件
> -v /docker/mysql/logs:/logs \ #挂载本地配置文件
> -v /docker/mysql/data:/var/lib/mysql \ #挂载本地配置文件
> -e MYSQL_ROOT_PASSWORD=xiaojiandnf \ #挂载本地配置文件