搭建LNMP架构 ---- Mysql配置
程序员文章站
2022-05-17 18:41:23
...
搭建LNMP架构 ---- Mysql配置
一:Mysql 概述
MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性 。
二:配置过程
1、安装需要的环境软件包
[aaa@qq.com ~]# yum install ncurses ncurses-devel bison cmake -y
2、创建运行用户 mysql ,并解压mysql 的压缩包
[aaa@qq.com system]# useradd -s /sbin/nologin mysql
cd /abc '创建运行用户'
[aaa@qq.com abc]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt/
3、在mysql-5.7.20 目录中编译cmake
[aaa@qq.com abc]# cd /opt/mysql-5.7.20/
[aaa@qq.com mysql-5.7.20]#
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ ‘安装路径’
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ ‘通讯文件’
-DSYSCONFDIR=/etc \ ‘配置文件所在目录’
-DSYSTEMD_PID_DIR=/usr/local/mysql \ ‘pid的路径’
-DDEFAULT_CHARSET=utf8 \ ‘字符集’
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ ‘存储引擎’
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
[aaa@qq.com mysql-5.7.20]# make && make install
[aaa@qq.com mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql ‘设置权限’
4、在/etc目录下, vim my.cnf 调整配置文件 (删除原有内容)
[aaa@qq.com mysql-5.7.20]# cd /etc/
[aaa@qq.com etc]# vim my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid_file = /usr/local/mysql/mysql.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
5、设置环境变量,并生效
[aaa@qq.com etc]# chown mysql.mysql /etc/my.cnf
[aaa@qq.com etc]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[aaa@qq.com etc]# echo 'export PATH' >> /etc/profile
[aaa@qq.com etc]# source /etc/profile ‘让/etc/profile修改的文件命令生效’
[aaa@qq.com etc]# cd /usr/local/mysql
[aaa@qq.com mysql]# ls
[aaa@qq.com mysql]# ls bin/
mysqld
...省略内容
6、初始化数据库
[aaa@qq.com mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
7、 保持路径不变,将服务复制到 /lib/systemd/system/路径下,可以用systemctl控制管理
[aaa@qq.com mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[aaa@qq.com mysql]# systemctl start mysqld ‘开启mysql服务’
[aaa@qq.com mysql]# netstat -ntap | grep mysqld ‘查看端口是否正常开启’
tcp6 0 0 :::3306 :::* LISTEN 26928/mysqld
[aaa@qq.com mysql]# systemctl enable mysqld ‘开机自启’
8、登录数据库,设置mysql数据库的密码 (密码默认是没有的,直接回车即可)
7、登录数据库,设置数据库的密码
[aaa@qq.com mysql]# mysql -u root -p
‘‘一直按回车键’’
[aaa@qq.com mysql]# mysqladmin -uroot -p password
Enter password: "按回车"
New password: “输入新的密码”
Confirm new password: “再次输入密码”
[aaa@qq.com mysql]# mysql -u root -p ‘登录数据库’
Enter password: ‘输入刚新设置的密码’
Mysql服务已配置完成。
推荐阅读
-
Centos搭建PHP5.3.8+Nginx1.0.9+Mysql5.5.17详细配置
-
CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)
-
redis服务器环境下mysql实现lnmp架构缓存
-
MySQL双主(主主)架构配置方案
-
LNMP小项目搭建,Centos7.6环境搭建Linux+nginx+mysql+php,wordpress个人博客的搭建(完整搭建步骤)
-
mysql 架构篇系列 4 复制架构一主一从搭建(半同步复制)
-
LAMP架构(2)——MySQL的搭建(适合小白)
-
Ubuntu编译安装HAprox+Keepalived+MySQL负载高可用架构(结合Docker容器配置)
-
LNMP服务器环境配置 (linux+nginx+mysql+php)
-
linux搭建的LNMP环境下的mysql授权远程连接