Centos7 Mysql5.7.25 tar包解压安装

mysql官网下载mysql-5.7.25-el7-x86_64.tar.gz

[root@centos7 src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-el7-x86_64.tar.gz

一、卸载系统自带的Mariadb

[root@centos7 src]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@centos7 src]# rpm -e --nodeps  mariadb-libs-5.5.60-1.el7_5.x86_64

二、删除/etc下my.cnf配置文件(如果存在的话)、检查mysql是否存在

[root@centos7 src]# rm -rf /etc/my.cnf
[root@centos7 src]# rpm -qa | grep mysql

三、检查mysql用户组、用户是否存在,不存在则创建

[root@centos7 src]# cat /etc/group | grep mysql 
[root@centos7 src]# cat /etc/passwd | grep mysql
[root@centos7 src]# groupadd mysql
[root@centos7 src]# useradd -g mysql mysql

四、解压mysql-5.7.25-el7-x86_64.tar.gz,移动到/usr/local/mysql5.7下,更改文件归属为mysql

[root@centos7 src]# tar -zxvf mysql-5.7.25-el7-x86_64.tar.gz 
[root@centos7 src]# mkdir -p /usr/local/mysql5.7
[root@centos7 src]# mv /usr/local/src/mysql-5.7.25-el7-x86_64/* /usr/local/mysql5.7/
[root@centos7 src]# mkdir /usr/local/mysql5.7/data
[root@centos7 src]# mkdir /usr/local/mysql5.7/log
[root@centos7 src]# touch /usr/local/mysql5.7/log/mysqld.log
[root@centos7 src]# chown -R mysql /usr/local/mysql5.7/
[root@centos7 src]# chgrp -R mysql /usr/local/mysql5.7/

五、安装

[root@centos7 mysql5.7]# /usr/local/mysql5.7/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/data/

报错:

2020-11-14 09:34:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-11-14 09:34:02 [ERROR]   Child process: /usr/local/mysql5.7/bin/mysqldterminated prematurely with errno= 32
2020-11-14 09:34:02 [ERROR]   Failed to execute /usr/local/mysql5.7/bin/mysqld --bootstrap --datadir=/usr/local/mysql5.7/data --lc-messages-dir=/usr/local/mysql5.7/share --lc-messages=en_US --basedir=/usr/local/mysql5.7
-- server log begin --
/usr/local/mysql5.7/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

缺少libnuma.so.1依赖,安装依赖

yum install -y libnuma*

 

六、新建配置文件my.cnf,启动

[root@centos7 mysql5.7]# vi /etc/my.cnf
[root@centos7 mysql5.7]# chown 777 /etc/my.cnf 
[mysqld]
basedir=/usr/local/mysql5.7/
datadir=/usr/local/mysql5.7/data
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
lower_case_table_names=1
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
max_allowed_packet=16M

[client]
port=3306

[mysqld_safe]
log-error=/usr/local/mysql5.7/log/mysqld.log

启动

[root@centos7 mysql5.7]# cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 mysql5.7]# chmod +x /etc/init.d/mysqld
[root@centos7 mysql5.7]# service mysqld start

七、添加环境变量

[root@centos7 ~]# vi /etc/profile

添加mysql环境变量

# MYSQL
export MYSQL_HOME="/usr/local/mysql5.7/"
export PATH="$PATH:$MYSQL_HOME/bin"

使环境变量生效

[root@centos7 ~]# source /etc/profile

八、获取初始密码,连接mysql,更改默认密码,允许远程访问

获取初始密码

[root@centos7 ~]# cat /root/.mysql_secret  
# Password set for user 'root@localhost' at 2019-03-02 09:09:05 
zffNQ>e(l/U;

修改密码

[root@centos7 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

允许远程访问

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> create user 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

远程连接还是连不上,telnet测试发现3306端口不通,原来是防火墙没有添加规则

[root@centos7 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent 
success
[root@centos7 ~]# firewall-cmd --reload
success

至此,mysql tar包安装结束~

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值