第一步:http://dev.mysql.com/downloads/mysql/#downloads下载安装包
mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
第二步:准备Xshell终端连接工具,如果没有安装lrzsz,先输入命令安装:yum -y install lrzsz
,rpm -qa lrzsz
确认安装是否成功,利用rz -y
上传安装包到所在位置
第三步:检查是否已经安装mysql,输入命令:rpm -qa|grep -i mysql
,如果已经安装了,就先卸载:rpm -e 这个位置填检查到的包名 --nodeps
第四步:添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组
[root@server01 local]# groupadd mysql
[root@server01 local]# useradd -r -g mysql mysql
useradd -r参数表示mysql用户是系统用户,不可用于登录系统
第五步:将二进制文件解压到指定的安装目录,我们这里指定为/usr/local
[root@server01 local]# tar zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
解压后发现名字太长,我们为它建立一个符号链接mysql,方便输入。
[root@server01 local]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
第六步:进入mysql文件夹,更改所属的组和用户
[root@server01 mysql]# chown -R mysql .
[root@server01 mysql]# chgrp -R mysql .
第七步:在mysql所在目录新建data
[root@server01 mysql]# mkdir data
第八步:在/usr/local/mysql/support-files目录下创建my_default.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.
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
第九步:拷贝,如果提示是否覆盖,y
[root@server01 mysql]# cp support-files/my_default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
第十步:初始化 mysqld
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
第十一步:初始化完成之后,查看日志,注意进入日志所在目录
[root@server01 data]# tailf mysqld.log
2019-10-22T03:17:06.212192Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-22T03:17:06.212314Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2019-10-22T03:17:06.212319Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2019-10-22T03:17:06.626203Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-10-22T03:17:06.694462Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-10-22T03:17:06.757488Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6d3f79db-f47a-11e9-be68-000c29fb312d.
2019-10-22T03:17:06.758350Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-10-22T03:17:07.434757Z 0 [Warning] CA certificate ca.pem is self signed.
2019-10-22T03:17:07.518937Z 1 [Note] A temporary password is generated for root@localhost: S72.5lAlM2FK
日志内有临时密码:
2019-10-22T03:17:07.518937Z 1 [Note] A temporary password is generated for root@localhost: S72.5lAlM2FK
第十二步:把启动脚本放到开机初始化目录
[root@server01 mysql]# cp support-files/mysql.server /etc/init.d/mysql
第十三步:启动mysql服务
[root@server01 mysql]# service mysql start
Starting MySQL. SUCCESS!
第十四步:登录mysql,密码为初始密码
[root@server01 mysql]# ./bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
第十五步:修改密码
mysql> set password=password('******');
Query OK, 0 rows affected, 1 warning (0.00 sec)
第十六步:添加远程访问
mysql> grant all privileges on *.* to root@'%' identified by '******';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
第十七步:退出
mysql> quit
Bye