MySQL-5.7.2安装
MySQL-5.7.2安装
一、下载
[root@master app]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
二、安装步骤
[root@master app]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@master app]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
# 新增mysql用户,并禁止shell登陆
[root@master app]# groupadd mysql
[root@master app]# useradd -r -g mysql -s /sbin/nologin mysql
#添加环境变量
[root@master app]# echo export PATH=/app/mysql/bin:$PATH >> /etc/profile
[root@master app]# source /etc/profile
#创建数据目录,且跟新权限
[root@master app]# mkdir /data/mysql -p
[root@master app]# chown -R mysql.mysql /app/*
[root@master app]# chown -R mysql.mysql /data/*
三、初始化mysql5.7数据库,(建库)
新特性重要说明:
5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合
3.密码过期时间180天
注释:5.6初始化的区别
/application/mysql/scripts/mysql_install_db --user=mysql --datadir=/application/mysql/data --basedir=/application/mysql
安装个依赖(如果报错的话)
[root@master ~]# yum install -y libaio-devel
方法一:
[root@master app]# mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/data/mysql
2020-11-03T22:58:14.478390Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-03T22:58:15.000423Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-03T22:58:15.151549Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-03T22:58:15.411250Z 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: 0e675d3c-1e28-11eb-801c-000c29af70c3.
2020-11-03T22:58:15.416616Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-03T22:58:15.418487Z 1 [Note] A temporary password is generated for root@localhost: vPc0AOjkI3#F
方法二 :
初始化数据,初始化管理员的密码为空
[root@master app]# rm -rf /data/mysql/*
[root@master app]# mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/data/mysql
四、书写默认配置文件
[root@master mysql]# cat /etc/my.cnf
[mysqld]
user=mysql
basedir=/app/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=tzh
五、配置启动脚本
[root@master mysql]# cd /app/mysql/support-files
[root@master support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/mysql/master.err'.
SUCCESS!
[root@master support-files]# cp mysql.server /etc/init.d/mysqld
六、使用systemd管理mysql
vim /etc/systemd/system/mysqld.service
[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=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
注意:将原来模式启动mysqld先关闭,然后再用systemd管理。
[root@master support-files]# ./mysql.server stop
Shutting down MySQL.. SUCCESS!
systemctl start/stop/restart/status mysqld
设置密码为123
mysqladmin -uroot -p password 123