1.下载安装包:
https://downloads.mysql.com/archives/community/
2.拷贝到/usr/local目录下,解压:
scp root@10.3.98.22:/home/download/software/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz .
tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql
3.创建mysql用户组及mysql用户:
groupadd mysql
useradd -g mysql mysql
4.赋权限:
chown -R mysql:mysql /usr/local/mysql
5.创建data目录,手动创建mysqld.log文件:
mkdir /home/mysql/data/
touch /home/mysql/mysqld.log
chown -R mysql:mysql /home/mysql
6.修改配置文件
cd /usr/local/mysql/support-files
cp ./my-default.cnf /etc/my.cnf
vi /etc/my.cnf ---修改base和data目录等配置,注意base就定义为/usr/local/mysql;validate_password_policy和validate_password_length如果配置了密码策略,启动会有问题,所以先给注释掉。my.cnf内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
socket=/home/mysql/mysql.sock
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#validate_password_policy=0
#validate_password_length=4
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /home/mysql/data
user=mysql
max_allowed_packet=500M
wait_timeout=288000
interactive_timeout=288000
character-set-server = utf8
explicit_defaults_for_timestamp=true
socket=/home/mysql/mysql.sock
log-error=/home/mysql/mysqld.log
lower_case_table_names=1
max_connections=1000
max_connect_errors = 2000
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
7.添加服务启动:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
修改基本配置:
vi /etc/init.d/mysql 修改base和data目录路径
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=
datadir=/home/mysql/data
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
查看my.cnf的权限
ls -l /etc/my.cnf
chmod 644 /etc/my.cnf
chown -R mysql:mysql /etc/my.cnf
8.初始化安装:
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
#生成证书bin/mysql_ssl_rsa_set
9.启动:
service mysql start
或 #以后台形式启动
bin/mysqld_safe --user=mysql &
#添加开机自启
chkconfig --add mysql
#验证是否添加成功
chkconfig --list mysql
#使用service命令查看mysql状态,以后可通过此命令操作mysql启动、关闭等
10.建立客户端软连接:
rm /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
11.查找初始密码:
grep 'temporary password' /home/mysql/mysqld.log
12.登录修改密码并设置权限:
mysql -u root -p
输入密码
SET PASSWORD = PASSWORD('root55');
grant all privileges on *.* to root@'%' identified by 'root55';
flush privileges;