MySQl 5.7.26 学习笔记-1-安装
目录
一、准备
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并解压
[[email protected] /]$ tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
### 用户的创建处理原始环境
[[email protected] /]$ useradd -s /sbin/nologin mysql
[[email protected] /]$ yum remove mariadb-libs-5.5.60-1.el7_5.x86_64 -y
### 设置环境变量
[[email protected] /]$ vim /etc/profile
export PATH=/application/mysql/bin:$PATH
[[email protected] /]$ source /etc/profile
[[email protected] /]$ mysql -V
mysql Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using EditLine wrapper
### 授权
[[email protected] /]$ chown -R mysql.mysql /application
[[email protected] /]$ chown -R mysql.mysql /data
### 初始化
[[email protected] /]$ 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
解决:
[[email protected] /]$ yum install -y libaio-devel
2.配置文件
[[email protected] /]$ 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
[[email protected] /]$ 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.启动数据库
[[email protected] /]$ systemctl start mysqld
4.启动数据库失败处理
测试,将/data/mysql/data/ibdata1 所属修改为root,启动数据库查看日志
手工调用数据库排查
[[email protected] data]$ /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
改回权限重启数据库
5.管理员密码的设定([email protected])
[[email protected] /]$ mysqladmin -uroot -p password [email protected]
Enter password:(因无初始密码,此处直接回车)
6.重置管理员密码
--skip-grant-tables #跳过授权表(很危险)
--skip-networking #跳过远程登录
6.1关闭数据库
[[email protected] /]$ systemctl stop mysqld
6.2 启动数据库到维护模式
[[email protected] /]$ mysqld_safe --skip-grant-tables --skip-networking &
6.3 登录并修改密码
[[email protected] ~]$ mysql
mysql> flush privileges;
mysql> alter user [email protected]'localhost' identified by '13456';
Query OK, 0 rows affected (0.01 sec)
6.4 重启数据库登录验证