Linux下安装mysql-5.7.28详细步骤
一、下载Mysql
下载地址:https://downloads.mysql.com/archives/community/
二、环境配置
检测系统是否自带Mysql
# rmp -qa|grep mysql
如果有进行强行卸载
# rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64
检测系统是否自带mariadb
# rpm -qa|grep mariadb
# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
# rpm -e --nodeps mariadb-5.5.64-1.el7.x86_64
# rpm -e --nodeps mariadb-server-5.5.64-1.el7.x86_64
用连接工具将下载的mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz上传到linux服务器/data/software/的目录下面
三、安装
进入/data/software/目录下解压
# tar -zxvf mysql-5.7.28.tar.gz
解压完成后重命名
# mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28
# mv mysql-5.7.28 /usr/local/
检查mysql组和用户是否存在,如果没有则创建
cat /etc/group|grep mysql
groupadd mysql
useradd -r -g mysql mysql #useradd -r参数表示mysql用户是系统用户,不可用于登录系统
安装数据库
创建data目录
cd
/usr/local/mysql-5.7.28
mkdir data
将/usr/local/mysql-5.7.28的所有者及所属组改为mysql
# chown -R mysql.mysql /usr/local/mysql-5.7.28
在/usr/local/mysql-5.7.28/support-files目录下创建my_default.cnf
# vim my_default.cnf
[mysqld]
#设置mysql的安装目录
basedir =/usr/local/mysql-5.7.28
#设置mysql数据库的数据存放目录
datadir = /usr/local/mysql-5.7.28/data
#设置端口
port = 3306
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /usr/local/mysql-5.7.28/data/mysqld.log
pid-file = /usr/local/mysql-5.7.28/data/mysqld.pid
#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
拷贝,是否覆盖,是
# cp my_default.cnf /etc/my.cnf
初始化Mysql
# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7.28/ --datadir=/usr/local/mysql-5.7.28/data/
如果报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or 就安装libaio,如果没有则跳过
yum install libaio
初始化完成之后查看日志
cat /usr/local/mysql-5.7.28/data/mysqld.log,蓝框里的是临时密码
把启动脚本放到开机初始化目录
cp support-files/mysql.server /etc/init.d/mysql
启动mysql
service mysql start
进入mysql并更改密码
cd /usr/local/mysql-5.7.28
./bin/mysql -u root -p
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;
添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
如果更改时报错:ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY',就先查询一下是否已更改,最后执行刷新。
重启mysql生效
service mysql restart