MySQL安装配置

一、安装步骤

MySQL下载官方网址:https://dev.mysql.com/downloads/mysql/

  1. 版本选择
    选择Generic版本
  2. 下载MySQL
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
  1. 解压
tar -zxf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
  1. 移动并重命名
mv mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql

二、配置

  1. 设置环境变量
[root@db01 ~]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@db01 ~]# source /etc/profile
  1. 创建mysql用户
useradd mysql
  1. 创建相关目录并授权
mkdir -p /data/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
  1. 初始化数据库

初始化方法一

[root@db01 ~]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2019-09-21T11:10:23.024138Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-09-21T11:10:24.321756Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-09-21T11:10:24.502952Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-09-21T11:10:24.567784Z 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: 68db32d2-dc60-11e9-a7ac-fa163eeb8fda.
2019-09-21T11:10:24.569709Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-09-21T11:10:24.570070Z 1 [Note] A temporary password is generated for root@localhost: 2iNfDjsiww+V

新特性重要说明
5.7开始,MySQL加入了全新的密码安全机制
1. 初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2. 密码复杂度: 长度超过12位
3. 密码过期时间180天

初始化方法二: 不加安全机制,关闭上述特性

rm -rf /data/mysql/*
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
2019-09-21T12:04:20.024078Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-09-21T12:04:21.322044Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-09-21T12:04:21.502184Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-09-21T12:04:21.567685Z 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: f2422f73-dc67-11e9-834b-fa163eeb8fda.
2019-09-21T12:04:21.570072Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-09-21T12:04:21.570367Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  1. 编辑配置文件
vim /etc/my.cnf

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock

[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>

三、服务管理

3.1 使用service管理

[root@db01 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

3.2 使用systemd管理

  1. 编辑配置文件
[root@db01 ~]# vim /etc/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
  1. 重新加载系统服务
[root@db01 ~]# systemctl daemon-reload
  1. 启动mysql
systemctl start mysqld
  1. 修改root密码
[root@db01 ~]# mysqladmin -uroot -p password 123
  1. 登录
[root@db01 ~]# mysql -uroot -p
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值