cd /home
mkdir service
mkdir log
mkdir conf
mkdir www
mkdir -p /home/conf/nginx
mkdir -p /home/conf/redis
mkdir -p /home/conf/tomcat
mkdir -p /home/log/nginx
mkdir -p /home/log/redis
mkdir -p /home/log/tomcat
#以上是建立文件夹
cd service
groupadd mysql
useradd -r -g mysql mysql
tar -zxvf mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.15-linux-glibc2.5-x86_64 mysql
chown -R mysql mysql
chgrp -R mysql mysql
#添加需要的依赖
yum -y install libaio
mysql/bin/mysqld --initialize --user=mysql --datadir=/home/service/mysql/data --basedir=/home/service/mysql
#这里注意,安装完成后在控制台的最后一行会打印出mysql生成的密码,这个要记录下,登录的时候需要,如果没有记录的话,有其他方式找到,这里默认是记录的情况。
#如果 /etc/my.cnf 没有的话,有没有都直接覆盖是可以的,以免造成遇到其他麻烦
cp /home/service/mysql/support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
#my.cnf中关键配置:
[mysqld]
basedir = /home/service/mysql
datadir = /home/service/mysql/data
port = 3306
character-set-server=utf8
#修改完成
cp /home/service/mysql/support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld
#修改mysqld中的
basedir=/home/service/mysql
datadir=/home/service/mysql/data
#添加开机自启动
mkdir -p /usr/local/mysql/bin
ln -s /home/service/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
chkconfig --level 35 mysqld on
#启动mysql
service mysql start
cd /home/service/mysql/bin
#登录mysql
./mysql -uroot -p
SET PASSWORD = PASSWORD('root');
flush privileges;
#添加远程访问权限
use mysql;
update user set host = '%' where user = 'root';
select host, user from user;
#重启生效
/etc/init.d/mysqld restart
如果远程不能访问,看看防火墙的端口是否开放了。
转载于:https://blog.51cto.com/bingowu/1876479