mysql5.7 安装

环境centos7.5  mysql5.7.20二进制包安装
[root@localhost local]# tar mysql-5.7.20-linux-glibc2.12-x86_64/ -C /usr/local
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# mkdir -p data log binlogs run
[root@localhost mysql]# cd ..
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@localhost mysql]# source /etc/profile
删除系统自带的my.cnf
[root@localhost mysql]# rm -f /etc/my.cnf
在/usr/local/mysql/etc/下创建my.cnf文件,加入如下参数,其他参数根据需要配置

[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535

skip-name-resolve
lower_case_table_names=1

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0

key_buffer_size = 64M

log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5

tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 0
query_cache_size = 0

server-id=1

初始化数据库
[root@localhost mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
在日志文件里会提示一个临时密码,记录这个密码
[root@localhost data]# grep 'temporary password' /usr/local/mysql/log/mysql_error.log 
2018-07-25T07:41:54.320139Z 1 [Note] A temporary password is generated for root@localhost: Af?sTwvon4oM
设置启动项
[root@localhost mysql]# cd /usr/lib/systemd/system
[root@localhost system]# vim mysqld.service

# Copyright (c) 2015, 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
#
# systemd service file for MySQL forking server

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/usr/local/mysql/run/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/run/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 65535

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

重新加载daemon
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl enable mysqld.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost system]# systemctl is-enabled mysqld
启动mysql
[root@localhost data]# systemctl start mysqld
修改密码
[root@localhost data]# mysql -uroot -p'Af?sTwvon4oM'
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '000000';
Query OK, 0 rows affected (0.00 sec)

环境centos7.5  rpm包安装
在MySQL官网中下载YUM源rpm安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
跳转文件夹
cd /myroles/roles/nginx/files/lnmp
安装mysql源
yum -y localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*" #下面三行结果
mysql-connectors-community/x86_64 MySQL Connectors Community                  3
mysql-tools-community/x86_64      MySQL Tools Community                       4
mysql57-community/x86_64          MySQL 5.7 Community Server                 18
安装mysql
yum -y install mysql-community-server
yum -y install mysql-community-devel
启动mysql #5.7后安装第一次启动会产生随机密码
systemctl start mysqld
if [ $? -eq 0 ];then
    echo "mysql start succeed"
fi
查看mysql启动状态
service mysqld status
设置开机启动
systemctl enable mysqld
systemctl daemon-reload
获取mysql默认生成的密码
tmppassword=`grep 'temporary password' /var/log/mysqld.log|awk -F " " '{print $NF}'`
2017-07-04T06:06:06.824762Z 1 [Note] A temporary password is generated for root@localhost: h8wob/ou+wpC
(冒号):后的就是自动生成的密码 h8wob/ou+wpC ,换成自己的密码
mysql -uroot -p"${tmppassword}" -e 'ALTER USER 'root'@'localhost' IDENTIFIED BY '123IsYourNewPassword!'
mysql>
更换密码
mysql> ALTER USER '30519root'@'localhost' IDENTIFIED BY '123IsYourNewPassword!'; 
注意:这里的新密码必须包含数字、小写或大写字母、特殊字符串。这个密码的复杂程度,和validate_password_policy的值有关。
Policy
Tests Performed
0 or LOW
Length
1 or MEDIUM
Length; numeric, lowercase/uppercase, and special characters
2 or STRONG
Length; numeric, lowercase/uppercase, and special characters; dictionary file
默认是1,即MEDIUM。如果想要降低密码复杂度,可以进入mysql后设置。
mysql> set global validate_password_policy=0;
至此,mysql安装完毕




















 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值