Linux安装mysql(Centos7、mysql5.7.36-gz版本)

  •  使用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/data

cat /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 --state

6、查看监听的端口
netstat -lnpt

7、ps -fe | grep mysql

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值