一、安装mysql5.7.28 二进制包安装
0、下载mysql安装包
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
1、环境准备
1.1、系统版本
[root@mysql ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
1.2、清理环境
[root@mysql ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@mysql ~]# yum -y remove mariadb-libs
1.3、创建用户和组
useradd mysql -s /sbin/nologin
[root@mysql ~]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)
1.4、创建相关目录
mkdir -p /app/database/ #创建软件目录
mkdir -p /data/3306/ #创建数据目录
mkdir -p /binlog/3306/ #创建日志目录
1.5、设置权限
chown -R mysql.mysql /app/ /data/ /binlog/
1.6、解压mysql5.7.28
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
1.7、创建软连接
ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
1.8、设置环境变量
vim /etc/profile
export PATH=/app/database/mysql/bin:$PATH
source /etc/profile
1.9、初始化数据库
mysql-5.7初始化方式
mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
----------------------------------初始化过程-------------------------------------
2020-03-08T13:29:39.740136Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-08T13:29:42.248896Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-08T13:29:42.624523Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-08T13:29:42.847225Z 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: de972b4b-6140-11ea-bc5c-000c29d66e4c.
2020-03-08T13:29:42.850263Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-08T13:29:44.254018Z 0 [Warning] CA certificate ca.pem is self signed.
2020-03-08T13:29:44.808748Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
------------------------------------初始化完成--------------------------------------
说明:出现以上信息初始化成功
mysql-5.6初始化方式
/app/database/mysql/scripts/mysql_install_db --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
1.10、设置配置文件
cat > /etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/app/database/mysql
datadir=/data/3306
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
EOF
1.11、复制mysql启动脚本
cp /app/database/mysql/support-files/mysql.server /etc/init.d/mysqld
1.12、启动mysql
启动方式1:
[root@mysql mysql]# /etc/init.d/mysqld start
启动方式2:centos6启动方式
[root@mysql mysql]# service mysqld start
启动方式3:centos7启动方式
[root@mysql mysql]# chkconfig --add mysqld
[root@mysql mysql]# systemctl start mysqld
1.13、登录mysql
[root@mysql mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 MySQL Community Server (GPL)
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>
1.14、更新root登录密码
update mysql.user set authentication_string=password('ljx@123') where user='root' and Host ='localhost';
1.15、配置root远程登录
grant all privileges on *.* to 'root'@'%' identified by 'oa123456' with grant option;
flush privileges;