1.下载连接
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
2.操作系统
CentOS Linux release 7.5.1804 (Core)
3.目录规划
软件目录
/application/mysql
数据目录
/data/mysql/data
二、安装1.初始化
### 上传安装包到/application/mysql并解压
[root@MySQL /]$ tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
### 用户的创建处理原始环境
[root@MySQL /]$ useradd -s /sbin/nologin mysql
[root@MySQL /]$ yum remove mariadb-libs-5.5.60-1.el7_5.x86_64 -y
### 设置环境变量
[root@MySQL /]$ vim /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@MySQL /]$ source /etc/profile
[root@MySQL /]$ mysql -V
mysql Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using EditLine wrapper
### 授权
[root@MySQL /]$ chown -R mysql.mysql /application
[root@MySQL /]$ chown -R mysql.mysql /data
### 初始化
[root@MySQL /]$ mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data
报错:
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:
[root@MySQL /]$ yum install -y libaio-devel
2.配置文件
[root@MySQL /]$ cat >/etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
EOF
[root@MySQL /]$ cat >/etc/systemd/system/mysqld.service <<EOF
> [Unit]
> Description=MySQL Server
> Documentation=man:mysqld(8)
> Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
> After=network.target
> After=syslog.target
> [Install]
> WantedBy=multi-user.target
> [Service]
> User=mysql
> Group=mysql
> ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
> LimitNOFILE = 5000
> EOF
3.启动数据库
[root@MySQL /]$ systemctl start mysqld
4.启动数据库失败处理
测试,将/data/mysql/data/ibdata1 所属修改为root,启动数据库查看日志
手工调用数据库排查
[root@MySQL data]$ /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
改回权限重启数据库
5.管理员密码的设定(root@localhost)
[root@MySQL /]$ mysqladmin -uroot -p password 1qaz@WSX123
Enter password:(因无初始密码,此处直接回车)
6.重置管理员密码
--skip-grant-tables #跳过授权表(很危险)
--skip-networking #跳过远程登录
6.1关闭数据库
[root@MySQL /]$ systemctl stop mysqld
6.2 启动数据库到维护模式
[root@MySQL /]$ mysqld_safe --skip-grant-tables --skip-networking &
6.3 登录并修改密码
[root@MySQL ~]$ mysql
mysql> flush privileges;
mysql> alter user root@'localhost' identified by '13456';
Query OK, 0 rows affected (0.01 sec)
6.4 重启数据库登录验证