php7编译mysql_CentOS7.2 编译安装MySQL 5.7.22 与 PHP7.4.3 mysql扩展 (第五章)

MySQL安装

前置操作 下载

[root@anonymous package]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.22.tar.gz

[root@anonymous package]# pwd

/package

[root@anonymous package]# ll | grep mysql

-rw-r--r-- 1 root root 48985783 Mar 4 2018 mysql-boost-5.7.22.tar.gz

[root@anonymous package]#

注意: 安装之前需要删除系统中的 mariadb

[root@anonymous package]# find / -name mariadb*

/usr/share/doc/mariadb-libs-5.5.64

/etc/ld.so.conf.d/mariadb-x86_64.conf

[root@anonymous package]# rpm -e mariadb-libs-5.5.64 --nodeps

[root@anonymous package]# find / -name mariadb*

[root@anonymous package]#

安装所需依赖, 可以 yum 命令安装

make-3.82-24.el7.x86_64

gcc-c++-4.8.5-39.el7.x86_64

cmake-2.8.12.2-2.el7.x86_64

bison-devel-3.0.4-2.el7.x86_64

libaio-0.3.109-13.el7.x86_64

libaio-devel-0.3.109-13.el7.x86_64

ncurses-devel-5.9-14.20130511.el7_4.x86_64

[root@anonymous package]# rpm -qa make gcc-c++ cmake bison-devel libaio libaio-devel ncurses-devel

make-3.82-24.el7.x86_64

gcc-c++-4.8.5-39.el7.x86_64

[root@anonymous package]# yum -y install cmake bison-devel libaio libaio-devel ncurses-devel

① 解压 mysql-boost-5.7.22.tar.gz 并进入解压出来的 mysql-5.7.22 目录

[root@anonymous package]# pwd

/package

[root@anonymous package]# ls | grep mysql

mysql-boost-5.7.22.tar.gz

[root@anonymous package]# tar -zxvf mysql-boost-5.7.22.tar.gz

[root@anonymous package]# cd mysql-5.7.22/

[root@anonymous mysql-5.7.22]# ls

boost configure.cmake INSTALL man README support-files

BUILD COPYING libbinlogevents mysql-test regex testclients

client dbug libbinlogstandalone mysys scripts unittest

cmake Docs libevent mysys_ssl sql VERSION

CMakeLists.txt Doxyfile-perfschema libmysql packaging sql-common vio

cmd-line-utils extra libmysqld plugin storage win

config.h.cmake include libservices rapid strings zlib

[root@anonymous mysql-5.7.22]#

安装mysql所在的路径为 /usr/study/ext/mysql, 其中data目录为存放数据的目录, log为日志文件目录

[root@anonymous ext]# pwd

/usr/study/ext

[root@anonymous ext]# tree /usr/study/ext/mysql/

/usr/study/ext/mysql/

├── data

└── log

2 directories, 0 files

[root@anonymous ext]#

用 cmake 编译并生成 makefile

[root@anonymous mysql-5.7.22]# cmake \

-DBUILD_CONFIG=mysql_release \ # 按照oracle生成官方版本的选项来编译程序

-DCMAKE_INSTALL_PREFIX=/usr/study/ext/mysql \ # MySQL安装的根目录

-DMYSQL_DATADIR=/usr/study/ext/mysql/data \ # MySQL数据库文件存放目录

-DSYSCONFDIR=/usr/study/ext/mysql \ # MySQL配置文件所在目录

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ # MySQL的sock文件目录

-DEXTRA_CHARSETS=all \ # 使MySQL支持所有的扩展字符

-DDEFAULT_CHARSET=utf8 \ # 设置默认字符集为utf8

-DDEFAULT_COLLATION=utf8_general_ci \ # 设置默认字符校对

-DWITH_BOOST=boost \ # 指定boost安装路径

-DWITH_MYISAM_STORAGE_ENGINE=1 \ # 编译myisam存储引擎,默认的存储引擎,不加也可以

-DWITH_INNOBASE_STORAGE_ENGINE=1 \ # 支持InnoDB存储引擎,这个也是默认安装的

-DMYSQL_TCP_PORT=3306 \ # MySQL的监听端口

-DENABLED_LOCAL_INFILE=1 \ # 启用加载本地数据

-DWITH_PARTITION_STORAGE_ENGINE=1 \ # 安装数据库分区, 不加也行

-DWITH_EMBEDDED_SERVER=OFF \

[root@anonymous mysql-5.7.22]# cmake \

> -DBUILD_CONFIG=mysql_release \

> -DCMAKE_INSTALL_PREFIX=/usr/study/ext/mysql \

> -DMYSQL_DATADIR=/usr/study/ext/mysql/data \

> -DSYSCONFDIR=/usr/study/ext/mysql \

> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

> -DEXTRA_CHARSETS=all \

> -DDEFAULT_CHARSET=utf8 \

> -DDEFAULT_COLLATION=utf8_general_ci \

> -DWITH_BOOST=boost \

> -DWITH_MYISAM_STORAGE_ENGINE=1 \

> -DWITH_INNOBASE_STORAGE_ENGINE=1 \

> -DMYSQL_TCP_PORT=3306 \

> -DENABLED_LOCAL_INFILE=1 \

> -DWITH_PARTITION_STORAGE_ENGINE=1 \

> -DWITH_EMBEDDED_SERVER=OFF

[root@anonymous mysql-5.7.22]# make -j 2 # 时间有点长,请耐心等待

[root@anonymous mysql-5.7.22]# make install

创建mysql用户 和 创建 mysql日志目录 注意: 要修改mysql用户的权限

[root@anonymous mysql]# groupadd -g 1001 mysql

[root@anonymous mysql]# useradd -g 1001 mysql

[root@anonymous mysql]# chown -R root:mysql /usr/study/ext/mysql/

[root@anonymous mysql]# chown -R mysql: /usr/study/ext/mysql/data/

[root@anonymous mysql]# chown -R mysql: /usr/study/ext/mysql/log/

在/usr/study/ext/mysql 目录下创建配置文件 my.cnf

[root@anonymous mysql]# pwd

/usr/study/ext/mysql

[root@anonymous mysql]# vim my.cnf

输入如下参数 wq 保存退出

[mysqld]

basedir=/usr/study/ext/mysql

datadir=/usr/study/ext/mysql/data

socket=/tmp/mysql.sock

log_error=/usr/study/ext/mysql/log/error.log

server-id=1

explicit_defaults_for_timestamp=true

设置环境变量

[root@anonymous mysql]# echo "export PATH=/usr/study/ext/mysql/bin:\$PATH" > /etc/profile.d/mysql.sh

[root@anonymous mysql]# source /etc/profile

[root@anonymous mysql]#

安装完毕需要初始化数据库

[root@anonymous mysql]# /usr/study/ext/mysql/bin/mysqld \

> --initialize-insecure \

> --user=mysql \

> --basedir=/usr/study/ext/mysql \

> --datadir=/usr/study/ext/mysql/data

[root@anonymous mysql]#

初始化完毕

[root@anonymous data]# pwd

/usr/study/ext/mysql/data

[root@anonymous data]# ll

total 110620

-rw-r----- 1 mysql mysql 56 Mar 29 10:42 auto.cnf

-rw-r----- 1 mysql mysql 417 Mar 29 10:42 ib_buffer_pool

-rw-r----- 1 mysql mysql 12582912 Mar 29 10:42 ibdata1

-rw-r----- 1 mysql mysql 50331648 Mar 29 10:42 ib_logfile0

-rw-r----- 1 mysql mysql 50331648 Mar 29 10:42 ib_logfile1

drwxr-x--- 2 mysql mysql 4096 Mar 29 10:42 mysql

drwxr-x--- 2 mysql mysql 4096 Mar 29 10:42 performance_schema

drwxr-x--- 2 mysql mysql 12288 Mar 29 10:42 sys

[root@anonymous data]#

设置开机启动mysql

[root@anonymous support-files]# pwd

/usr/study/ext/mysql/support-files

[root@anonymous support-files]# ll

total 24

-rw-r--r-- 1 root mysql 773 Mar 4 2018 magic

-rwxr-xr-x 1 root mysql 1061 Mar 29 09:38 mysqld_multi.server

-rwxr-xr-x 1 root mysql 914 Mar 29 09:38 mysql-log-rotate

-rwxr-xr-x 1 root mysql 10600 Mar 29 09:38 mysql.server

[root@anonymous support-files]# cp mysql.server /etc/init.d/mysqld

[root@anonymous support-files]# ll /etc/init.d/mysqld

-rwxr-xr-x 1 root root 10600 Mar 29 10:46 /etc/init.d/mysqld

[root@anonymous support-files]# /etc/init.d/mysqld start

Starting MySQL. [ OK ]

[root@anonymous support-files]# netstat -ltpn | grep 3306

tcp6 0 0 :::3306 :::* LISTEN 17308/mysqld

[root@anonymous support-files]#

[root@anonymous support-files]# /sbin/chkconfig mysqld on

在 /usr/study/ext/mysql 目录下安全导向配置 mysql_secure_installation

[root@anonymous mysql]# pwd

/usr/study/ext/mysql

[root@anonymous mysql]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

... skipping.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

All done!

[root@anonymous mysql]#

测试连接是否成功

[root@anonymous mysql]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

mysql>

开启 root 远程连接权限

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_mysql |

+---------------------------+

| columns_priv |

| db |

| engine_cost |

| event |

| func |

| general_log |

| gtid_executed |

| help_category |

| help_keyword |

| help_relation |

| help_topic |

| innodb_index_stats |

| innodb_table_stats |

| ndb_binlog_index |

| plugin |

| proc |

| procs_priv |

| proxies_priv |

| server_cost |

| servers |

| slave_master_info |

| slave_relay_log_info |

| slave_worker_info |

| slow_log |

| tables_priv |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

31 rows in set (0.00 sec)

mysql> SELECT host,user FROM user;

+-----------+---------------+

| host | user |

+-----------+---------------+

| localhost | mysql.session |

| localhost | mysql.sys |

| localhost | root |

+-----------+---------------+

3 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'This is your password';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> SELECT host,user FROM user;

+-----------+---------------+

| host | user |

+-----------+---------------+

| % | root |

| localhost | mysql.session |

| localhost | mysql.sys |

| localhost | root |

+-----------+---------------+

4 rows in set (0.00 sec)

mysql>

window下用 Navicat Premium 测试连接

5a6346885ee9

connect.jpg

② 在PHP7.4.3中扩展 mysqli 和 pdo_mysql

[root@anonymous ext]# pwd

/package/php-7.4.3/ext

[root@anonymous ext]# ls | grep mysqli

mysqli

[root@anonymous ext]# ls | grep pdo_mysql

pdo_mysql

[root@anonymous ext]#

cd 进入 /package/php-7.4.3/ext/mysqli

[root@anonymous mysqli]# pwd

/package/php-7.4.3/ext/mysqli

[root@anonymous mysqli]# phpize

Configuring for:

PHP Api Version: 20190902

Zend Module Api No: 20190902

Zend Extension Api No: 320190902

[root@anonymous mysqli]# ls

autom4te.cache configure.ac mysqli_driver.c mysqli_mysqlnd.h mysqli_result_iterator.c tests

build config.w32 mysqli_exception.c mysqli_nonapi.c mysqli_warning.c

config.h.in CREDITS mysqli_fe.c mysqli_priv.h php_mysqli.h

config.m4 mysqli_api.c mysqli_fe.h mysqli_prop.c php_mysqli_structs.h

configure mysqli.c mysqli_libmysql.h mysqli_report.c run-tests.php

[root@anonymous mysqli]# ./configure --with-php-config=/usr/study/ext/php/bin/php-config

[root@anonymous mysqli]# make && make install pdo_mysql

cd 进入 /package/php-7.4.3/ext/pdo_mysql

[root@anonymous pdo_mysql]# pwd

/package/php-7.4.3/ext/pdo_mysql

[root@anonymous pdo_mysql]# phpize

Configuring for:

PHP Api Version: 20190902

Zend Module Api No: 20190902

Zend Extension Api No: 320190902

[root@anonymous pdo_mysql]# ls

autom4te.cache configure get_error_codes.php php_pdo_mysql.h tests

build configure.ac mysql_driver.c php_pdo_mysql_int.h

config.h.in config.w32 mysql_statement.c php_pdo_mysql_sqlstate.h

config.m4 CREDITS pdo_mysql.c run-tests.php

[root@anonymous pdo_mysql]# ./configure --with-php-config=/usr/study/ext/php/bin/php-config

[root@anonymous pdo_mysql]# make && make install

修改php.ini配置文件 加入 extension=mysqli 和 extension=pdo_mysql

[root@anonymous pdo_mysql]# vim /usr/study/ext/php/lib/php.ini

5a6346885ee9

mysqli.jpg

查看是否有扩展

[root@anonymous ~]# php --ri pdo_mysql

pdo_mysql

PDO Driver for MySQL => enabled

Client API version => mysqlnd 7.4.3

Directive => Local Value => Master Value

pdo_mysql.default_socket => no value => no value

[root@anonymous ~]# php --ri mysqli

mysqli

MysqlI Support => enabled

Client API library version => mysqlnd 7.4.3

Active Persistent Links => 0

Inactive Persistent Links => 0

Active Links => 0

Directive => Local Value => Master Value

mysqli.max_links => Unlimited => Unlimited

mysqli.max_persistent => Unlimited => Unlimited

mysqli.allow_persistent => On => On

mysqli.rollback_on_cached_plink => Off => Off

mysqli.default_host => no value => no value

mysqli.default_user => no value => no value

mysqli.default_pw => no value => no value

mysqli.default_port => 3306 => 3306

mysqli.default_socket => no value => no value

mysqli.reconnect => Off => Off

mysqli.allow_local_infile => Off => Off

[root@anonymous ~]#

到此MySQL5.7.22安装完毕

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值