登录
首页 >  数据库 >  MySQL

php环境篇:linux编译安装mysql5.7

来源:SegmentFault

时间:2023-01-18 11:40:45 129浏览 收藏

哈喽!今天心血来潮给大家带来了《php环境篇:linux编译安装mysql5.7》,想必大家应该对数据库都不陌生吧,那么阅读本文就都不会很困难,以下内容主要涉及到MySQL、Linux、PHP,若是你正在学习数据库,千万别错过这篇文章~希望能帮助到你!

mysql编译安装

添加用户

useradd -s /usr/sbin/nologin -r mysql

下载源码包以及解压

wget https://cdn.mysql.com//archives/mysql-5.7/mysql-boost-5.7.21.tar.gz
tar -zxf mysql-boost-5.7.21.tar.gz
cd mysql-5.7.21
安装扩展依赖

yum remove mariadb-libs

yum install gcc -y
yum install gcc-c++ -y
yum install cmake -y
yum install libaio -y
yum install ncurses-devel -y
创建mysql的安装目录及数据库存放目录

mkdir -p /data/db/mysql
mkdir -p /data/log/mysql
编译安装mysql

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_SYSTEMD=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost

make -j8 && make install
检验是否安装成功

[root@root mysql-5.7.12]#    cd /usr/local/mysql/
[root@root mysql]#    ls
bin      data  include  man         mysql.sock.lock  README  support-files
COPYING  docs  lib      mysql.sock  mysql-test       share
新建目录

mkdir -p /data/db/mysql/
mkdir -p /data/log/mysql/
增加配置文件

mkdir /usr/local/mysql/etc
touch /usr/local/mysql/etc/my.cnf
ln -s /usr/local/mysql/etc/my.cnf /usr/local/etc
修改权限

chown -R mysql:mysql /usr/local/mysql/*
chown -R mysql:mysql /data/db/mysql /data/log/mysql
生成初始化密码

cd /usr/local/mysql

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/db/mysql

bin/mysql_ssl_rsa_setup

vim /data/log/mysql/error.log

查看初始化密码
grep 'temporary password' /data/log/mysql/error.log
将mysql的启动服务添加到系统服务中

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system

mkdir -p /var/run/mysqld/
chown mysql:mysql /var/run/mysqld

systemctl start mysqld
service mysql start
启动mysql

service mysqld start

检查mysql启动是否正常
service mysqld status 或者 ps -ef | grep mysql

设置mysqld服务开机自启动
systemctl enable mysqld.service

检查mysqld开机自启动是否设置成功
systemctl list-dependencies | grep mysqld
修改mysql密码,以及远程连接权限

 ALTER USER 'root'@'localhost' IDENTIFIED BY 'Studytime%';
use mysql;
select host, user from user;
update user set host = '%' where user = 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Studytime%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

今天关于《php环境篇:linux编译安装mysql5.7》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表