您现在的位置是:首页 > 技术人生 > 服务器相关服务器相关

Centos7 mysql5.7.25 tar包解压安装

高晓波2019-03-02【服务器相关】人已围观

简介1、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
2、卸载系统

1、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

2、卸载系统自带的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

3、删除/etc下my.cnf配置文件(如果存在的话)、检查mysql是否存在
[root@centos7 src]# rm -rf /etc/my.cnf
[root@centos7 src]# rpm -qa | grep mysql

4、检查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

5、解压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/

6、安装
[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/

7、新建配置文件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

8、添加环境变量
[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

9、获取初始密码,连接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包安装结束~

Tags:mysql   centos

很赞哦! ()

文章评论