mysql安装
1.上传安装包并解压
tar -xvf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
2.修改目录
mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
3. 检查mysql组和用户是否存在,如果没有则创建
cat /etc/group|grep mysql
groupadd mysql
useradd -r -g mysql mysql
4. 创建data目录
cd mysql
mkdir data
5.修改mysql目录的所有者及所属组改为mysql
chown -R mysql:mysql /mnt/mysql
6.在mysql/support-files目录下创建my_default.cnf
cd support-files/
vim my_default.cnf
[mysqld]
socket=/tmp/mysql.sock
skip-name-resolve
#开启定时策略
event_scheduler=ON
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/mnt/mysql
# 设置mysql数据库的数据的存放目录
datadir=/mnt/mysql/data
# 允许最大连接数
max_connections=1000
max_user_connections=3000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqld_safe]
#是否区分大小写:0-区分大小写,1-不区分大小写
log-error=/mnt/mysql/data/mysqld.log
pid-file=/mnt/mysql/data/mysqld.pid
7.替换掉 /etc/my.cnf并修改权限
cp my_default.cnf /etc/my.cnf
chmod 644 /etc/my.cnf
8.编译并安装最后一行是密码
/mnt/mysql/bin/mysqld --user=mysql --basedir=/mnt/mysql --datadir=/mnt/mysql/data --initialize
9.配置自动启动
cp support-files/mysql.server /etc/init.d/mysql
cp support-files/mysql.server /etc/init.d/mysql
ln -s /mnt/mysql/bin/mysql /usr/bin
10.登录并修改密码建立远程链接
service mysql start
mysql -uroot -p
set password=password('123456');
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
11.添加端口3306,并重启防火墙
firewall-cmd --add-port=3306/tcp --permanent
systemctl restart firewalld
firewall-cmd --zone=public --list-ports