二进制包安装
下载二进制包
#wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
解压包
#tar zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
安装库文件
#yum install libaio
移动目录
#mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
移动到/usr/local/mysql
#cd /usr/local/mysql
添加用户
#useradd -M -s /sbin/nologin mysql
初始化环境
#bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
目录所属组改为mysql用户
#chown -R mysql .
创建目录
#mkdir /var/run/mysqld
更改目录权限
#chown mysql /var/run/mysqld
创建配置文件
#vi my.conf
[mysqld]
daemonize = on
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = /var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
max_connections = 1024
log-error = /usr/local/mysql/mysqld.log
system管理mysql
#vi /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Service]
User=mysql
Group=mysql
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.conf
LimitNOFILE=5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
[Install]
WantedBy=multi-user.target
#systemctl start mysqld 启动mysql服务
#systemctl status mysqld
#systemctl stop mysqld
查看监听端口
#netstat -antp | grep 3306
进入数据库
#bin/mysql -uroot -p
修改密码
#ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; #后面一定要加分号
设置开机启动
#systemctl enable mysqld
# 下载mysql源安装包 官网默认8.0YUM源
在这个网站下载: http://dev.mysql.com/downloads/repo/yum/
rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
下载5.7 YUM源
#wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
安装yum源
#rpm -Uvh mysql57-community-release-el7-8.noarch.rpm
yum安装
#yum install mysql-community-server