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

RedHat6.5/CentOS6.5安装Mysql5.7.20的教程详解

程序员文章站 2022-03-21 10:57:23
下载rpm安装包 mysql官网: 选择版本下载: 可以使用wget命令下载: [root@localhost opt]#wget https://cd...

下载rpm安装包

mysql官网:

选择版本下载:

RedHat6.5/CentOS6.5安装Mysql5.7.20的教程详解

可以使用wget命令下载:

[root@localhost opt]#wget https://cdn.mysql.com//downloads/mysql-5.7/mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar

注意redhat的版本和系统位数。

查看依赖的库

[root@localhost opt]# yum search libaio
[root@localhost opt]# yum install libaio

查看系统之前是否有安装过mysql相关版本

[root@localhost opt]# rpm -qa | grep mysql
[root@localhost opt]# rpm -qa | grep mariadb

RedHat6.5/CentOS6.5安装Mysql5.7.20的教程详解

有则删除,有几个删除几个

[root@localhost opt]# rpm -e mariadb-libs-5.5.44-2.el7.x86_64 --nodeps

安装

按照顺序安装软件包

[root@localhost opt]# rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm
[root@localhost opt]# rpm -ivh mysql-community-libs-5.7.20-1.el6.x86_64.rpm
[root@localhost opt]# rpm -ivh mysql-community-client-5.7.20-1.el6.x86_64.rpm
[root@localhost opt]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm

创建mysql用户和用户组

[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql -s /bin/false mysql

创建mysql数据存放目录

[root@localhost /]# mkdir -p /data/mysql
[root@localhost /]# chown mysql.mysql /data/mysql
[root@localhost /]# ll -d /data/mysql/
drwxr-xr-x. 2 mysql mysql 6 9月 17 17:37 /data/mysql/

修改/etc/my.cnf配置文件

[mysqld]
init-connect='set names utf8mb4'
default-storage-engine=innodb
character-set-server=utf8mb4
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password=off
sql_mode=strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_substitution
lower_case_table_names=1
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4

初始化mysql

[root@localhost /]# /usr/sbin/mysqld --initialize --user=mysql

查看初始化密码

[root@localhost /]# grep "root@localhost" /var/log/mysqld.log

登录mysql并修改密码

mysql> set password = password('123456');

允许远程访问(不推荐)

mysql> use mysql; 
mysql> select host,user,password from user; 
mysql> update user set password=password('xxxxxx') where user='root'; 
mysql> update user set host='%' where user='root' and host='localhost'; 
mysql> flush privileges;

总结

以上所述是小编给大家介绍的redhat6.5/centos6.5安装mysql5.7.20的教程详解,希望对大家有所帮助