Linux安装Mysql及Nginx详细步骤
2020-12-14 本文已影响0人
小宝_6d94
一、Mysql安装
1、检测系统是否自带Mysql
>rmp -qa|grep mysql
如果有进行强行卸载
>rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64
2、检测系统是否自带mariadb
>rpm -qa|grep mariadb
>rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
3、解压安装包
>tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
4、重命名
>mv mysql-5.7.32-linux-glibc2.12-x86_64 mysql-5.7
>mv mysql-5.7 /usr/local/
5、检查mysql组和用户是否存在,如果没有则创建
>cat /etc/group|grep mysql
>groupadd mysql
>useradd -r -g mysql -s /bin/false mysql
6、安装数据库
>cd /usr/local/mysql-5.7
>mkdir data
7、将/usr/local/mysql-5.7的所有者及所属组改为mysql
>chown -R mysql.mysql /usr/local/mysql-5.7
8、在/usr/local/mysql-5.7/support-files目录下创建my_default.cnf
>cd support-files/
>vim my_default.cnf
[mysqld]
#设置mysql的安装目录
basedir =/usr/local/mysql-5.7
#设置mysql数据库的数据存放目录
datadir = /usr/local/mysql-5.7/data
#设置端口
port = 3306
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /usr/local/mysql-5.7/data/mysqld.log
pid-file = /usr/local/mysql-5.7/data/mysqld.pid
#允许时间类型的数据为零(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
9、拷贝配置文件到/etc/
>cp my_default.cnf /etc/my.cnf
10、初始化Mysql
>cd ../bin/
>./mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7/ --datadir=/usr/local/mysql-5.7/data/
如果报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or 就安装libaio,如果没有则跳过
>yum install libaio
>./mysqld --initialize --user=mysql --basedir=/usr/local/mysql-5.7/ --datadir=/usr/local/mysql-5.7/data/
11、查看临时密码
>cat /usr/local/mysql-5.7/data/mysqld.log
12、把启动脚本放到开机初始化目录
>cp support-files/mysql.server /etc/init.d/mysql
12、启动mysql
service mysql start
二、修改密码
1、进入mysql
>cd /usr/local/mysql-5.7/bin/
>.mysql -u root -p
2、设置密码
>set password=password('123456');
>grant all privileges on *.* to root@'%' identified by '123456';
>flush privileges;
3、设置远程访问
>use mysql;
>update user set host='%' where user = 'root';
> flush privileges;
三、nginx安装
1、下载解压
>tar -zxvf nginx-1.19.5.tar.gz
>mv nginx-1.19.5 nginx1.19
>mv nginx1.19 /usr/local/
>yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
>cd /usr/local/nginx1.19/
>./configure --prefix=/usr/local/nginx
>make
>make install