源码编译安装LAMP(Linux, Apache ,Mysql ,PHP)-------------- (连载篇(二)----Mysql)

安装mysql

步骤一:安装mysql

yum -y install \
gcc \
gcc-c++ \
make \
ncurses \
ncurses-devel \
bison \
cmake

步骤二:创建mysql程序账户

useradd -s /sbin/nologin mysql

步骤三:到opt 软件包所在目录下

cd /opt
tar zxf mysql-boost-5.7.20.tar.gz

步骤四:编译安装

cd /opt/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 \
-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


make &&  make  install             ###先make -j3   然后make install 也可以  -j3是你核心数,最大不要超过虚拟机的核心数         

步骤五:数据库目录进行权限调整

chown -R mysql:mysql /usr/local/mysql/

步骤六:建立调整配置文件

vi /etc/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/mysqld.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

chown mysql:mysql /etc/my.cnf   #配置文件更改属主

步骤七:设置环境变量


echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile

echo 'export PATH' >> /etc/profile

source /etc/profile

步骤八:初始化数据库

cd /usr/local/mysql/

bin/mysqld \
--initialize-insecure \                          #初始化
--user=mysql \                                   # 指定程序用户mysql
--basedir=/usr/local/mysql \               #指定咱们之前建立的调整配置
--datadir=/usr/local/mysql/data          #指定咱们之前建立的调整配置

步骤九:启动mysql数据库

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


#方便操作管理,可以使用systemctl命令启动mysql

systemctl enable mysqld
systemctl start mysqld
netstat -anpt | grep 3306
tcp6       0      0 :::3306                 :::*                  LISTEN      53975/mysqld

步骤十:设置mysql数据库密码

mysqladmin -u root -p password  //刚开始没密码是空的直接回车,然后输入密码,再此确认密码,这是在root账户下运行的

mysql -u root -p     ##这个命令敲下,提示要输入密码,这个就是刚才设置的密码

你可能感兴趣的:(企业平台服务搭建)