RedHat7.4安装tar格式MySQL5.7.13步骤,规避了所有可能出现的问题

本教程需要Linux命令基础和SQL基础,有问题欢迎留言。

版本:

Red Hat Enterprise Linux Server release 7.4 (Maipo)
MySQL5.7.13


约定目录:
安装文件下载目录:/data/software
Mysql目录安装位置:/usr/local/mysql
数据库保存位置:/data/mysql
日志保存位置:/data/log/mysql


环境需要,若已安装则跳过:
安装wget:
yum install wget
安装libaio:
yum install -y libaio
安装vim:
yum install vim


创建目录:
su root
mkdir /data/software
mkdir /data/mysql
mkdir /data/log
mkdir /data/log/mysql


下载mysql:
cd /data/software
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz


解压并修改文件夹名:
cd /usr/local
tar -xzvf /data/software/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.13-linux-glibc2.5-x86_64 mysql


创建mysql用户和用户组,改变目录所有者:
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
chown -R mysql /data/mysql


配置参数:
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
bin/mysql_ssl_rsa_setup --datadir=/data/mysql


修改系统文件:
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql
    修改如下内容:
    basedir=/usr/local/mysql
    datadir=/data/mysql
vim /etc/my.cnf
    整个文件内容如下:
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
    # *** default location during install, and will be replaced if you
    # *** upgrade to a newer version of MySQL.
    [mysqld_safe]
    open-files-limit = 1024
    log-error = /data/log/mysql/mysql_3306.err
    
    [client]
    default-character-set = utf8
    socket = /usr/local/mysql/mysql.sock
    port = 3306
    
    [mysql]
    default-character-set = utf8
    no-auto-rehash
    
    [mysqld]
    
    ##修改完密码后需要删除
    skip-grant-tables 
    
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    
    # These are commonly set, remove the # and set as required.
    basedir = /usr/local/mysql
    datadir = /data/mysql
    server_id = 1
    socket = /usr/local/mysql/mysql.sock
    max_connections = 200
    
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M 
    
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


启动mysql,并登录:
cd /usr/local/mysql
bin/mysqld_safe --user=mysql &
bin/mysql --user=root


修改密码,mysql命令行输入:
update mysql.user set authentication_string=password('密码') where user='root' and host='127.0.0.1' or host='localhost';
alter user 'root'@'localhost' identified by '密码';
flush privileges;
exit


删除绕过密码配置:
vim /etc/my.cnf
    删除[mysqld]下的skip-grant-tables


重启电脑,并重新启动mysql:
reboot
su root
cd /usr/local/mysql
bin/mysqld_safe --user=mysql &
bin/mysql --user=root -p


如需要外网访问,则修改外网访问性,无需访问则跳过:
mysql命令行下输入:
use mysql
select host,user from user;
    若显示如下:
    +-----------+-----------+
    | host      | user      |
    +-----------+-----------+
    | localhost | mysql.sys |
    | localhost | root      |
    +-----------+-----------+
则:

update user set host='%' where user='root';

flush privileges;

exit


重启电脑,并重新启动mysql,外网即可连接mysql:
reboot
su root
cd /usr/local/mysql
bin/mysqld_safe --user=mysql &


添加系统路径:
vim /etc/profile
    最下方添加:
    export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile


配置自动启动:
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on


重启电脑:
reboot


完成!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值