MySQL之环境准备

1 环境准备

(1)准备虚拟机
	IP:192.168.159.51/24	hostname:db01
(2)清理历史环境
	[root@db01 ~]# yum remove mariadb-libs -y
(3)创建用户和组
	[root@db01 ~]# useradd mysql -s /sbin/nologin -M
	[root@db01 ~]# id mysql
	uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
(4)创建相关目录
	# 创建软件目录
	mkdir -p /app/database/
	# 创建数据目录
	mkdir -p /data/3306/
	# 创建日志目录
	mkdir -p /binlog/
(5)设置用户权限
	[root@db01 ~]# chown -R mysql.mysql /app/ /data/ /binlog/

2 上传并解压 MySQL 软件

cd /app/database
tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql

3 设置环境变量

echo 'export PATH=/app/database/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
4 初始化系统库表
mysqld --initialize-insecure  --user=mysql --basedir=/app/database/mysql --datadir=/data/3306
=============初始化过程=======================
2020-06-11T07:48:34.417254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-11T07:48:34.553270Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-06-11T07:48:34.583094Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-06-11T07:48:34.639441Z 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: f3d4c6b6-abb7-11ea-a9dd-000c29c8dc7e.
2020-06-11T07:48:34.640374Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-06-11T07:48:34.641712Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
============容易遇到的报错====================数据路径已有文件
2020-06-11T07:50:23.815049Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-11T07:50:23.816427Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2020-06-11T07:50:23.816458Z 0 [ERROR] Aborting

5 扩展:初始化方式

# 5.7
(1)mysqld --initialize
	1. 初始化完成后,会有12位临时密码,但必须在使用MySQL之前重置这个密码
	2. 密码管理使用严格模式:3种密码复杂度以上
(2)mysqld --initialize-insecure

# 5.6
	/app/database/mysql/scripts/mysql_install_db --user=mysql --basedir=/app/data/base/mysql --datadir=/data/3306

6 配置文件设置

cat > /etc/my.cnf << EOF
[mysqld]
user=mysql
basedir=/app/database/mysql
datadir=/data/3306
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
EOF

7 准备MySQL启动脚本

cd /app/database/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
# CentOS 6
service mysqld start
# CentOS 7
chkconfig --add mysqld
systemctl start mysqld

附录:相关软件

链接: https://pan.baidu.com/s/1bEx_Y3cfVAykhfjPqDI6OQ 提取码: kwi5

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值