- 下载安装包:MySQL :: Download MySQL Community Server (Archived Versions)
- 下载地址(mysql-5.7.36-el7-x86_64.tar.gz):https://downloads.mysql.com/archives/get/p/23/file/mysql-community-embedded-5.7.36-1.el7.x86_64.rpm
- 使用wget下载(linux环境必须能链接外网)
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36-el7-x86_64.tar.gz
- 将压缩包放在 /usr/local/目录中
- 解压:
tar -zxvf mysql-5.7.36-el7-x86_64.tar.gz
- 将解压好的文件放在 /usr/local/mysql中
mv mysql-5.7.36-el7-x86_64 /usr/local/mysql
- 创建data、log目录
- 创建mysql.log、mysql.pid、mysql.sock文件
- 并创建mysql用户组并赋予mysql目录权限
cd /usr/local/
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql mysql
- 修改/etc/my.cnf配置文件,若是没有,直接创建(具体意思请移步百度)
[client]
port=3306
socket=/usr/local/mysql/log/mysql.sock
default-character-set=utf8[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/log/mysql.sock
log-error=/usr/local/mysql/log/mysql.log
pid-file=/usr/local/mysql/log/mysql.pid
character-set-server=utf8
# 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/mariadb/mariadb.log
# pid-file=/var/run/mariadb/mariadb.pid#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
- 初始化,完成后,初始密码再/usr/local/mysql/log/mysql.log中存放
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/datacat /usr/local/mysql/log/mysql.log
- 启动mysql,并设置开机自启,修改初始化密码,赋予外部链接权限:
cp support-files/mysql.server /etc/init.d/mysqld
#开机自启
chkconfig --add mysqld 或者 systemctl enable mysqld#启动mysql
systemctl start mysqld#登陆Mysql
bin/mysql -uroot -p
Enter password:
mysql: [Warning] Using a password on the command line interface can be insecure.
......
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#修改密码为root
set password=password("root");#赋权
grant all privileges on *.* to root@'%' identified by 'root' with grant option;update user set user.Host='%' where user.User='root'; --报错不用理会
flush privileges;
exit;
- 添加mysql 软连接并重启mysql服务。
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
- 其他
1、开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开放3306端口
firewall-cmd --zone=public --remove-port=3306/tcp --permanent #关闭3306端口
firewall-cmd --reload # 配置立即生效
2、查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
2、查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
3、关闭防火墙
如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估
systemctl stop firewalld.service
4、开启防火墙
systemctl start firewalld.service
5、查看防火墙状态
firewall-cmd --state6、查看监听的端口
netstat -lnpt7、ps -fe | grep mysql