MySQl 5.7.26 学习笔记-1-安装

目录

一、准备

1.下载连接 

2.操作系统

3.目录规划

二、安装

1.初始化

2.配置文件

3.启动数据库

4.启动数据库失败处理

5.管理员密码的设定(root@localhost)

6.重置管理员密码


一、准备

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

image.png

 

报错:

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

image.png

 

4.启动数据库失败处理

测试,将/data/mysql/data/ibdata1 所属修改为root,启动数据库查看日志

image.png

 

image.png

 

手工调用数据库排查

[root@MySQL data]$ /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf 

image.png

改回权限重启数据库

image.png

 

5.管理员密码的设定(root@localhost)

[root@MySQL /]$ mysqladmin -uroot -p password 1qaz@WSX123

Enter password:(因无初始密码,此处直接回车)

image.png

 

6.重置管理员密码

--skip-grant-tables  #跳过授权表(很危险)

--skip-networking    #跳过远程登录

6.1关闭数据库

[root@MySQL /]$ systemctl stop  mysqld

6.2 启动数据库到维护模式

[root@MySQL /]$ mysqld_safe --skip-grant-tables --skip-networking &

image.png

6.3 登录并修改密码

[root@MySQL ~]$ mysql

mysql> flush privileges;

mysql> alter user root@'localhost' identified by '13456';

Query OK, 0 rows affected (0.01 sec)

image.png

6.4 重启数据库登录验证

image.png

6.5 修改密码

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;  ---本地

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;   ---远程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值