mysql部署

您所在的位置:网站首页 mysql页大小 mysql部署

mysql部署

2023-03-14 22:58| 来源: 网络整理| 查看: 265

二进制安装mysql

下载二进制安装包

mysql 5.7

https://dev.mysql.com/downloads/mysql/5.7.html

mysql 8.0

https://dev.mysql.com/downloads/mysql/

解压,移动至/usr/local/mysql

tar -zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/mysql tar -xvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz

创建mysql的专用用户

useradd -M -s /sbin/nologin -r mysql #-M不创建主目录,-s /sbin/nologin不允许登录,-r创建的是系统用户

创建data、log目录

mkdir -p /usr/local/mysql/{data,log}

修改所属主和所属组

chown -R mysql.mysql /usr/local/mysql/

初始化

./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2022-08-14T06:27:29.155027Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-08-14T06:27:29.717996Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-08-14T06:27:29.794023Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-08-14T06:27:29.858797Z 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: 2c2fa8fd-1b9a-11ed-8fe7-0800276dbfeb. 2022-08-14T06:27:29.861624Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-08-14T06:27:29.901443Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-08-14T06:27:29.901452Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-08-14T06:27:29.901810Z 0 [Warning] CA certificate ca.pem is self signed. 2022-08-14T06:27:29.923322Z 1 [Note] A temporary password is generated for root@localhost: :8:6VKt(BjUv#此处为初始密码

修改配置文件

[root@youxi1 mysql]# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 socket=/usr/local/mysql/mysql.sock character-set-server=utf8 log-error=/usr/local/mysql/log/mysqld.log pid-file=/tmp/mysqld.pid user=mysql [mysql] socket=/usr/local/mysql/mysql.sock [client] socket=/usr/local/mysql/mysql.sock

配置环境变量

echo "PATH=$PATH:$HOME/bin:/usr/local/mysql/bin" >>/etc/profile source /etc/profile

将mysql添加进服务

vim /usr/lib/systemd/system/mysqld.service[Unit] Description=MYSQL server After=network.target [Install] WantedBy=multi-user.target [Service] Type=forking TimeoutSec=0 PermissionsStartOnly=true ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize $OPTIONS ExecReload=/bin/kill -HUP -$MAINPID #这里-HUP可以是改成-s HUP,就变成强制杀进程,有需要可以改,下面也一样 ExecStop=/bin/kill -QUIT $MAINPID #-s QUIT是强制杀进程 KillMode=process LimitNOFILE=65535 Restart=on-failure RestartSec=10 RestartPreventExitStatus=1 PrivateTmp=false

启动mysql

systemctl start mysqld.service yum安装mysql mysql安装

1、首先检查是否有安装过mysql

rpm -qa | grep mysql

2、将已经安装过的软件卸载掉。注意:这样的卸载是不彻底,不过这里够用了

yum remove 软件名

3、下载mysql的repo源

#mysql 5.7 wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm#mysql 8.0 wget http://repo.mysql.com//mysql80-community-release-el7-6.noarch.rpm

4、安装mysql-community-release-el7-5.noarch.rpm包

#mysql 5.7 rpm -ivh mysql57-community-release-el7-7.noarch.rpm#mysql 8.0 rpm -ivh mysql80-community-release-el7-6.noarch.rpm

5、安装mysql

sudo yum install mysql-server -y 启动mysql systemctl start mysqld.service

在日志文件中找出密码

grep 'temporary password' /var/log/mysqld.log 修改密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'; flush privileges; 授权root远程登录 use mysql; create user 'root'@'%' identified by '123456'; grant all privileges on *.* to 'root'@'%' with grant option; 问题描述

源 “MySQL 5.7 Community Server” 的 GPG 密钥已安装,但是不适用于此软件包。请检查;

从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥 源 "MySQL 5.7 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。 失败的软件包是:mysql-community-server-5.7.37-1.el7.x86_64 GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

解决方法:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3