二进制安装mysql5.7

直入正题

以下为安装步骤
(1)关闭防火墙

systemctl stop firewalld.service 
systemctl disable firewalld.service #禁止开机自启动
firewall-cmd --state  #显示为not running即为关闭状态

selinux 关不关感觉没什么影响
selinux关闭方法

setenforce 0 #重启后失效
vi /etc/selinux/config #把SELINUX=enforce改成disabled,重启电脑,永久生效

(2)检查是否已安装mysql,或者mariadb
如果系统中已有安装会有冲突的,尤其是mariadb,centos7安装时是默认安装的,所以在装系统的时候,最好去掉这个选项。

rpm -qa |grep mysql

如有

yum remove mysql*

同样mariadb检查一遍

rpm -qa |grep mariadb
yum remove mariadb*

(3)创建mysql用户和用户组

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -d /home/mysql -g mysql -m mysql
[root@localhost ~]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:
无效的密码: 密码少于 7 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

(4)创建目录并更改权限

[root@localhost ~]# mkdir -p /opt/mysql5.7  #安装mysql的base目录
[root@localhost ~]# mkdir -p /Mysql/my3306/{data,tmp,log}   #默认3306端口,多实例的话可使用3307,3308....等端口
[root@localhost ~]# cd /Mysql/my3306/
[root@localhost my3306]# ls
data  log  tmp
[root@localhost my3306]# mkdir -p /Mysql/my3306/log/{binlog,iblog}
[root@localhost my3306]# cd log/
[root@localhost log]# ls
binlog  iblog

更改目录权限

[root@localhost ~]# chown -R mysql:mysql /Mysql/my3306
[root@localhost ~]# chown -R mysql:mysql /opt/mysql5.7

(5)解压mysql tar包,并将添加到系统环境变量
[root@localhost vm_win_public]# tar -xzf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /opt
[root@localhost opt]# mv mysql-5.7.19-linux-glibc2.12-x86_64/* mysql5.7/ #移动至mysql5.7目录下
将bin添加到系统环境变量
vi /etc/profile #所有用户添加环境变量,重启依旧有效
在末尾加上:
PATH=$PATH:/opt/mysql5.7/bin
export PATH
最后 source /etc/profile 重新读取下配置文件
(6)初始化mysql数据库

root@localhost data]# mysqld --initialize --user=mysql --basedir=/opt/mysql5.7 --datadir=/Mysql/my3306/data
2019-10-11T08:48:02.858806Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-11T08:48:03.060795Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-10-11T08:48:03.092030Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-10-11T08:48:03.171779Z 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: d60c9920-ec03-11e9-bb68-000c29cdd83d.
2019-10-11T08:48:03.173732Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-10-11T08:48:03.174641Z 1 [Note] A temporary password is generated for root@localhost: Jw9i(?wojYek

最后的:Jw9i(?wojYek 就是你的临时密码,一定要保存下来,登陆mysql要用到
如果初始化的过程中有[error],可用于通过错误提示来解决问题,并且当错误解决后一定要清空/my3306/data目录下的所有内容,否则会报:

[root@localhost opt]# mysqld --initialize --user=mysql --basedir=/opt/mysql5.7 --datadir=/Mysql/my3306/data
2019-10-11T08:47:14.336663Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-11T08:47:14.338605Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-10-11T08:47:14.338633Z 0 [ERROR] Aborting44

(7)编辑my.cnf 控制文件
vi /etc/my.cnf 编辑配置文件
以下是配置文件的内容,也是启动mysql的必要配置,实际使用过程中可以根据使用需要设定相应参数
[mysqld]
basedir=/opt/mysql5.7
datadir=/Mysql/my3306/data
port=3306
pid-file = /Mysql/my3306/data/mysql.pid
user = mysql
socket=/Mysql/my3306/tmp/mysql.sock
bind-address = 0.0.0.0
server-id = 1
character-set-server = utf8

[client]
port=3306
socket=/Mysql/my3306/tmp/mysql.sock

[mysql]
socket=/Mysql/my3306/tmp/mysql.sock

(8)添加并启动mysql服务
将 mysql.server文件拷贝至/etc/init.d/目录下
cp /opt/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
编辑 /etc/init.d/mysqld 填写basedir和datadir信息
vi /etc/init.d/mysqld

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/opt/mysql5.7           #填入
datadir=/Mysql/my3306/data       

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.

保存并退出

启动mysql服务

[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/Mysql/my3306/data/localhost.localdomain.err'.
. SUCCESS! 
[root@local

(9)登陆mysql并修改密码
密码就是前面(6)中所记录的

[mysql@localhost ~]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.19

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql>

更改初始密码

mysql> set password for root@localhost = password('新密码');  
mysql> flush privileges

安装完成=。=

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章