下载mysql
搜狐镜像:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
检查环境
- 是否安装mysql
rpm -qa|grep -i mysql
- 是否安装MariaDB
rpm -qa|grep -i mariadb
- 卸载命令
yum -y remove xxx
- 准备安装包
mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz - 是否安装libaio
rpm -qa|grep libaio
- 安装libaio
yum install libaio-devel.x86_64
解压安装包并重命名
tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql-5.7.29
创建用户和用户组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
授予目录权限
chown -R mysql.mysql /usr/software/mysql
创建data文件夹
mkdir data
初始化数据库
/usr/software/mysql/mysql-5.7.29/bin/mysqld --user=mysql --basedir=/usr/software/mysql/mysql-5.7.29 --datadir=/usr/software/mysql/mysql-5.7.29/data --initialize
- 记下临时密码 在完成后最后一行
配置文件
vim /etc/my.cnf
[mysqld]
datadir=/usr/software/mysql/mysql-5.7.29/data
basedir=/usr/software/mysql/mysql-5.7.29
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
#跳过密码验证,忘记密码 可以设置,然后修改密码,再关闭
#skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# include all files from the config directory
!includedir /etc/my.cnf.d
将mysql加入服务
cp /usr/software/mysql/mysql-5.7.29/support-files/mysql.server /etc/init.d/mysql
修改目录basedir datadir
vim /etc/init.d/mysql
basedir=/usr/software/mysql/mysql-5.7.29
datadir=/usr/software/mysql/mysql-5.7.29/data
//开机启动
chkconfig mysql on
//创建目录
mkdir /etc/my.cnf.d/
启动服务
service mysql start
配置环境变量
vim /etc/profile
export PATH=$PATH:/usr/software/mysql/mysql-5.7.29/bin
//使配置生效
source /etc/profile
登录mysql修改密码、设置远程
mysql -uroot -p
alter user ‘root‘@‘localhost‘ identified by ‘201619706‘;
flush privileges;
use mysql;
update user set user.Host=‘%‘ where user.User=‘root‘;
flush privileges;
exit;
//重启服务
service mysql restart