1.查看是否有安装mariadb

    1. yum list installed | grep mariadb
    2. yum remove mariadb

    2.上传解压文件

    1. tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
    2. mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql

    3.创建数据目录

    1. mkdir -p /data/mysql/data

    4.添加mysql用户及用户组

    1. groupadd mysql
    2. useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql

    5.更改所属的组和用户

    1. cd /usr/local/mysql
    2. chown -R mysql .
    3. chgrp -R mysql .
    4. chown -R mysql /data/mysql

    6.安装初始化
    百度云安装问题记录

    1. error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
    2. # yum 安装的libnuma.so.1,但安装时默认安装的是32的,但db2需要的是64位的
    3. yum remove libnuma.so.1
    4. yum -y install numactl.x86_64
    1. cd /usr/local/mysql
    2. bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
    3. 2021-03-30T10:18:25.212584Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    4. 2021-03-30T10:18:26.237192Z 0 [Warning] InnoDB: New log files created, LSN=45790
    5. 2021-03-30T10:18:26.356956Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    6. 2021-03-30T10:18:26.459079Z 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: 43fe917f-9141-11eb-a515-00163e3019ff.
    7. 2021-03-30T10:18:26.460035Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    8. 2021-03-30T10:18:27.546222Z 0 [Warning] CA certificate ca.pem is self signed.
    9. 2021-03-30T10:18:28.087215Z 1 [Note] A temporary password is generated for root@localhost: vi!g5T1lK(t2

    7.修改 mysql 配置文件

    1. vi /usr/local/mysql/support-files/mysql.server
    2. basedir=/usr/local/mysql
    3. datadir=/data/mysql/data
    4. cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

    8.修改 my.cnf 文件

    1. vi /etc/my.cnf
    2. [mysqld]
    3. port = 3306
    4. basedir=/usr/local/mysql
    5. datadir=/data/mysql/data
    6. max_connections=200
    7. default-storage-engine=INNODB
    8. lower_case_table_names=1
    9. max_allowed_packet=64M
    10. sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

    9.启动并登录mysql

    1. /etc/init.d/mysqld start
    2. [root@tcloud mysql]# /etc/init.d/mysqld start
    3. Starting MySQL.Logging to '/data/mysql/data/tcloud.err'.
    4. .. ERROR! The server quit without updating PID file (/data/mysql/data/tcloud.pid).
    5. # 查看日志进行文件处理
    6. /usr/local/mysql/bin/mysql -u root -p'r3qz>ar.0=gK'

    10.修改root用户密码

    1. set password=password('tcloud@2021');
    2. # 授权否则 Navicat 无法连接
    3. grant all privileges on *.* to root@'%' identified by 'tcloud@2021';
    4. flush privileges;
    5. quit;

    11.将 MySQL 加入 Service 系统服务

    1. # 配置环境变量
    2. vim /etc/profile
    3. export MYSQL_HOME="/usr/local/mysql"
    4. export PATH="$PATH:$MYSQL_HOME/bin"
    5. . /etc/profile
    6. # 启动
    7. chkconfig --add mysqld
    8. chkconfig mysqld on
    9. service mysqld restart
    10. service mysqld status

    12.其他配置

    1. # 查看端口号
    2. netstat -lntup|grep 3306
    3. # mysql后台启动
    4. bin/mysqld_safe --defaults-file=/data/mysql-5.7.28/my.cnf --user=root &
    5. # 配置文件不生效(权限过大)