欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux下的mysql二进制安装

程序员文章站 2022-06-04 08:10:54
...

第一步 安装前工作

1、创建两个文件夹

在 根目录下,不要在root目录下,不然初始配置还会出现以下错误

mysqld: Can't change dir to '/root/data/mysql/' (Errcode: 13 - Permission denied)
2020-03-19T04:28:43.032786Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-19T04:28:43.041858Z 0 [ERROR] failed to set datadir to /root/data/mysql/
2020-03-19T04:28:43.041895Z 0 [ERROR] Aborting

所以要保证在根目录下

–这是root目录下

[[email protected] ~]

–这是根目录下

[[email protected] ~]# cd ..
[[email protected] /]# 
[[email protected] /]#mkdir application
[[email protected] /]#mkdir tools

2、将mysql解压包放到tools文件夹下,并解压

[[email protected] /]# cd tools
[[email protected] /]# ll
-rw-r--r--. 1 root root 713496499 3月  19 10:19 mysql-5.7.24-el7-x86_64.tar.gz
[[email protected] tools]# tar xf mysql-5.7.24-el7-x86_64.tar.gz 
[[email protected] tools]# mv mysql-5.7.24-el7-x86_64 /root/application/mysql

3、卸载不可用的东西

[[email protected] /]## rpm -qa|grep mariadb
[[email protected] /]## yum -y remove  mariadb-libs-5.5.64-1.el7.x86_64 

4、创建用户组和配置环境变量

  [[email protected] /]# useradd -s /sbin/nologin mysql
    [[email protected] /]# vi /etc/profile
    export PATH=/root/application/mysql/bin:$PATH
    [[email protected] /]# source /etc/profile
    [[email protected] /]# mysql -V
    mysql  Ver 14.14 Distrib 5.7.24, for el7 (x86_64) using  EditLine wrapper

5、创建数据文件和一些授权

[[email protected] /]# mkdir -p data/mysql
[[email protected] /]# chown -R mysql.mysql application/*
[[email protected] /]# chown -R mysql.mysql data/*

第二步 安装

1、初始化

[[email protected] /]# --initialize  --user=mysql --basedir=/application/mysql --datadir=/data/mysql

注:可能有三种错误

第一、缺少libaio-devel 软件包

[[email protected] /]# install -y libaio-devel

第二、/data/mysql 有文件

[[email protected] /]# rm -rf /data/mysql/*

第三、Can’t change dir to

2、配置默认配置文件

 [[email protected] /]# /etc/my.cnf
    [mysqld]
    user=mysql
    basedir=/application/mysql
    datadir=/data/mysql
    server_id=6
    port=3306
    socket=/tmp/mysql.sock
    [mysql]
    socket=/tmp/mysql.sock
    port=3306

3、配置启动脚本

[[email protected] /]#  cd /application/mysql/support-files
[[email protected] support-files]# ./mysql.server start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
. SUCCESS! 
[[email protected] support-files]# cp mysql.server  /etc/init.d/mysqld

4、使用systemd管理mysql

 [[email protected] /]#vi /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=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    LimitNOFILE = 5000

用systemd来管理

[[email protected] /]# pkill mysqld
[[email protected] /]#systemctl  start/stop/restart/status  mysqld

第三步 若密码忘记修改密码

 [[email protected] /]#systemctl  stop  mysqld
    [[email protected] /]# mysqld_safe --skip-grant-tables --skip-networking &
        mysql>flush privileges;
        mysql>use mysql;
        mysql>alter user [email protected]'localhost' identified by '123';
        mysql>quit;
    [[email protected] ~]# mysql -uroot -p
    Enter password: (123)





	


相关标签: mysql学习