二. MySQL 安装
大约 1 分钟
二. MySQL 安装
MySQL 5.x.x 版本
安装
centos
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
# 以上两步可以替换为:
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server mysql
systemctl start mysqld.service
# 如果出现 GPG 错误,是由于Mysql的GPG升级了,需要重新获取
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
windows
test
详情
5.7 版本默认要求修改密码
grep "password" /var/log/mysqld.log
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
centos
grep "password" /var/log/mysqld.log
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
windows
test
MySQL 5.7.x 版本
安装
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
# 以上两步可以替换为:
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server mysql
systemctl start mysqld.service
# 如果出现 GPG 错误,是由于Mysql的GPG升级了,需要重新获取
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# 因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:
yum -y remove mysql57-community-release-el7-10.noarch
MySQL 5.6.x 版本
安装
wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum install --downloadonly --downloaddir=/root/mysql56/ mysql-community-server
MySQL 服务管理
1. sys-v
cd ./mysql/support-files/
# sys-v 方式: service sshd restart
./mysql.server start
# or
cp ./mysql/support-files/mysql.server /etc/init.d/mysqld
# 本质上是执行的 mysqld_safe 脚本 ,再执行的 ./mysql/bin/mysqld
service mysqld start
2. systemd
# 7 版本建议的方式: systemd
vi /etc/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
[Install]
WantedBy=multi-user.target
[service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=5000
3. 维护性
Mysqld_safe --skip-grant-tables --skip-networking &
4. 查看状态
# 查看状态
netstat -lnp | grep mysqld
netstat -lnp | grep 3306
ps -ef | grep mysqld
systemctl status mysqld
ss -tupnl | grep mysql
ss -tupln | grep 3306
lsof -i :3306