MySQL实战一:二进制安装



1:下载mysql5.7
#wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz



2:复制到其他电脑
#scp mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz [email protected]:/root/



安装依赖包 
#yum install libaio


3:解压mysql
#tar zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz


移动目录到 
#mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql


转到mysql目录
#cd /usr/local/mysql


4:创建etc和logs目录
#mkdir {etc,logs}


5:创建用户
#useradd -s /sbin/nologin -M mysql     #-s 指定SHELL -M 不创建家目录



6:初始化并记录随机密码
#/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql




7:设置文件所有者
#chown -R mysql .        #这里是在/usr/local/mysql里面设置,这个命令是吧包含mysql目录都设置mysql用户所有


8:创建配置文件
#vi etc/my.cnf
[mysqld]
daemonize=on
user=mysql
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
bind-address=0.0.0.0
pid-file=/usr/local/mysql/mysqld.pid
character-set-server=utf8
collation-server=utf8_general_ci
max_connections=1024
log-error=/usr/local/mysql/logs/mysqld.log
default-storage-engine=InnoDB




9:创建systemctl管理文件
#vi /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.cnf
LimitNOFILE=5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

[Install]
WantedBy=multi-user.target



10:启动服务,设置开机启动
#systemctl start mysqld
#systemctl enable mysqld

查看服务启动是否成功
#ps -ef |grep mysql
#netstat -antp |grep 3306


11:设置系统环境变量
#export PATH=$PATH:/usr/local/mysql/bin

按G到最后一行,在其末尾添加如下代码
#vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
export PATH

#使用source使其生效
#source /etc/profile

查看变量是否设置成功
#echo $PATH



12:进入mysql修改密码
#/usr/local/mysql/bin/mysql -uroot -p

mysql> alter user 'root'@'localhost' identified by '123456';




13:开放防火墙端口
#firewall-cmd --zone=public --add-port=3306/tcp --permanent
#firewall-cmd --reload
#firewall-cmd --list-ports







CentOS7关闭防火墙和selinux
直接上命令 
在root用户下 
systemctl stop firewalld 
systemctl disable firewalld 
systemctl status firewalld 

临时关闭selinux 
setenforce 0 
永久关闭selinux 
#vi /etc/selinux/config 
把SELINUX=enforcing 改成 SELINUX=disabled 
重启电脑就可以了























猜你喜欢

转载自blog.csdn.net/qq_28710983/article/details/80934244