首页 > 数据库 >mysql部署

mysql部署

时间:2022-08-14 15:48:45浏览次数:78  
标签:27 部署 local usr 2022 mysql rpm

二进制安装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

标签:27,部署,local,usr,2022,mysql,rpm
From: https://www.cnblogs.com/yy9knsg/p/16585529.html

相关文章

  • docker 启动mysql:5.7
    docker启动mysql容器报错commandwas:mysqld--verbose--help--log-bin-index=/tmp/tmp.9eG6SycqdRmysqld:Can'treaddirof'/etc/mysql/conf.d/'(Errcod......
  • 20220814 idea_springboot_启动 Cannot load driver class: com.mysql.cj.jdbc.
    1问题Cannotloaddriverclass:com.mysql.cj.jdbc.Driver 2解决方案2.1已解决2.1.1首先,去查看项目中MySQL的版本如果找不到,说......
  • mysql-查询
    1.去重:selectDISTINCTname fromtable;2.空值(NULL)参与运算查询时会导致查询结果为NULL,可以在该字段加入 IFNULL(name, need_value)  来进行一个条件判断。3.......
  • Visual Studio 部署连接至远端 WSL 的 CMake 环境
    需求虽然CMAKE是"跨平台"的,但是这实际上说的是API的问题,我这里的需求不涉及多套API的问题,我只会使用"跨开发平台"这一点。也即是交叉编译,在Windows下开发Lin......
  • 使用LOAD_FILE()函数在MySQL数据库中插入BLOB字段的正确方法
    1.检查文件存不存在。 SELECTLOAD_FILE('C:/ProgramData/MySQL/MySQLServer8.0/Uploads/pic/11.jpg')ASRESULT;2.检查文件大小是否小于允许的最大字节。 showva......
  • 数据库与MySQL
    数据库什么是数据?data描述事物的符号记录称为数据,描述事物的符号既可以是数字,也可以是文字、图片,图像、声音、语言等,数据由多种表现形式,它们都可以经过数字化后存入计算......
  • mysql 8.0.28 查询语句执行顺序实测结果
    TL;NRs根据实测结果,MySQL8.0.28中SQL语句的执行顺序为:(8)SELECT(5)DISTINCT<select_list>(1)FROM<left_table>(3)<join_type>JOIN<right......
  • Linux下yum安装mysql 遇到的问题Can't open and lock privilege tables: Table 'mysql
    今天在linux下安装mysql时执行servicemysqldstart时,mysql总是启动失败后来查看mysql日志:/var/log/mysqld.log,发现有个Can'topenandlockprivilegetables:Table'......
  • 时序数据库influxdb-1.8.9部署记录步骤
    时序数据库部署步骤1.influxdb是目前比较流行的时间序列数据库。何谓时间序列数据库?什么是时间序列数据库,最简单的定义就是数据格式里包含Timestamp字段的数据,比如某一......
  • mysql安装
    目录win版5.x及8.xmsi版win版5.x及8.xmsi版基本都是下一步,注意左边从上到下,可能要下载c++依赖库。官方下载地址:https://dev.mysql.com/downloads/installer/1步:2......