1.查看是否有安装mariadb
yum list installed | grep mariadb
yum remove mariadb
2.上传解压文件
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql
3.创建数据目录
mkdir -p /data/mysql/data
4.添加mysql用户及用户组
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
5.更改所属的组和用户
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
chown -R mysql /data/mysql
6.安装初始化
百度云安装问题记录
error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# yum 安装的libnuma.so.1,但安装时默认安装的是32的,但db2需要的是64位的
yum remove libnuma.so.1
yum -y install numactl.x86_64
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
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).
2021-03-30T10:18:26.237192Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-03-30T10:18:26.356956Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
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.
2021-03-30T10:18:26.460035Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-03-30T10:18:27.546222Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-30T10:18:28.087215Z 1 [Note] A temporary password is generated for root@localhost: vi!g5T1lK(t2
7.修改 mysql 配置文件
vi /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/data/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
8.修改 my.cnf 文件
vi /etc/my.cnf
[mysqld]
port = 3306
basedir=/usr/local/mysql
datadir=/data/mysql/data
max_connections=200
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=64M
sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
9.启动并登录mysql
/etc/init.d/mysqld start
[root@tcloud mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/data/tcloud.err'.
.. ERROR! The server quit without updating PID file (/data/mysql/data/tcloud.pid).
# 查看日志进行文件处理
/usr/local/mysql/bin/mysql -u root -p'r3qz>ar.0=gK'
10.修改root用户密码
set password=password('tcloud@2021');
# 授权否则 Navicat 无法连接
grant all privileges on *.* to root@'%' identified by 'tcloud@2021';
flush privileges;
quit;
11.将 MySQL 加入 Service 系统服务
# 配置环境变量
vim /etc/profile
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
. /etc/profile
# 启动
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
service mysqld status
12.其他配置
# 查看端口号
netstat -lntup|grep 3306
# mysql后台启动
bin/mysqld_safe --defaults-file=/data/mysql-5.7.28/my.cnf --user=root &
# 配置文件不生效(权限过大)