安装依赖包,7. 创建boost文件夹并复制boost文件到

作者: www.9159.com  发布:2019-11-16
  1. 安装环境:CentOS 7 64位    MySQL 5.7

Centos7安装mysql-5.7.11

第一次在Centos安装MySQL,遇到很多问题,过程中一些问题分享下,有不足的地方,请指教~~

一.环境
1.Centos7 全安装(一些基本的软件都安装了)
2.mysql版本5.7.11

二.安装mySql准备
1.依赖
# yum install -y gcc-c++ make cmake bison bison-devel ncurses-devel libaio-devel perl
# yum install -y perl-Data-Dumper

2.mysql用户以及用户组
查看是否已经创建了:
# cat /etc/passwd | grep mysql
# cat /etc/group | grep mysql

没有创建则新建mysql用户以及用户组:
# groupadd mysql
# useradd -r -g mysql mysql

3.解压源码包
# tar -zxv -f mysql-5.7.11.tar.gz

4.确认硬盘空间,mysql大概需要2G的安装空间
# df -h

三.安装mysql
1.cmake安装
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
  -DWITH_MYISAM_STORAGE_ENGINE=1
  -DWITH_INNOBASE_STORAGE_ENGINE=1
  -DWITH_MEMORY_STORAGE_ENGINE=1
  -DWITH_READLINE=1
  -DENABLED_LOCAL_INFILE=1
  -DMYSQL_DATADIR=/usr/local/mysql/data
  -DMYSQL_USER=mysql
  -DMYSQL_TCP_PORT=3306
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/share/doc/boost-1.53.0

报错:CMake Error at cmake/boost.cmake:81 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
解决:检查是否安装了boost
如果安装了,在cmake添加 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost的安装目录(这时,先下载boost_1_59_0.tar.gz,并把boost_1_59_0.tar.gz复制到boost的安装目录比较好,centos安装下载的话,可能会报"Timeout was reached"错误)
如果没安装,
# yum search boost
# yum install -y boost.x86_64

添加了boost之后,再次运行
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
  -DWITH_MYISAM_STORAGE_ENGINE=1
  -DWITH_INNOBASE_STORAGE_ENGINE=1
  -DWITH_MEMORY_STORAGE_ENGINE=1
  -DWITH_READLINE=1
  -DENABLED_LOCAL_INFILE=1
  -DMYSQL_DATADIR=/usr/local/mysql/data
  -DMYSQL_USER=mysql
  -DMYSQL_TCP_PORT=3306
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/share/doc/boost-1.53.0

2.编辑并安装
2.1 编译(时间会比较久,大概半小时左右)
# make

2.2 安装
# make install

2.3 修改配置文件/etc/my.cnf
[mysqld]
#basedir是新添加进去的,原来没有
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in

[mysqld_safe]
#这个目录很重要,当启动mysql报错时,错误日志将在这个文件下
log-error=/usr/local/mysql/logs/mysql.log
#配置localhost.localdomain.pid路径,以免报错Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/localhost.localdomain.pid).
pid-file=/usr/local/mysql/localhost.localdomain.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

2.4 修改目录拥有者
# chown -R mysql:mysql /usr/local/mysql

2.5 添加MySQL服务
在mysql安装目录下
# cp /support-files/mysql.server /etc/init.d/mysql

四.启动mysql
1.启动mysql服务
# service mysql start

2.启动mysql
2.1 登录(在mysql安装目录的bin下)
# mysql -uroot -p

报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决:使用mysql指定的mysql.sock目录
# mysql -uroot -p -S /usr/local/mysql/mysql.sock

2.2 修改密码
mysql> update user set authentication_string=PASSWORD("vst123456") where user='root';

五.遇到过的问题
1.问题:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
描述:在mysql第一次登录遇到
解决:在 /etc/my.cnf 的 mysqld下面添加 skip-grant-tables
如下,省掉了注释:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock

symbolic-links=0

skip-grant-tables

[mysqld_safe]
log-error=/usr/local/mysql/logs/mysql.log
pid-file=/usr/local/mysql/localhost.localdomain.pid

!includedir /etc/my.cnf.d

2.问题:(1)ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid)
(2)ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/mysql.sock'
描述:在mysql第一次登录遇到
解决:之前在没有配置 /etc/my.cnf 的 socket 和 pid-file 之前经常遇到,因为这两个参数原先是有默认值的,并不是编译安装时的指定
路径,因为在配置了指定路径之后,再也没有遇到过
如下,省掉了注释:
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock

symbolic-links=0

skip-grant-tables

[mysqld_safe]
log-error=/usr/local/mysql/logs/mysql.log
pid-file=/usr/local/mysql/localhost.localdomain.pid

!includedir /etc/my.cnf.d

3.问题:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
描述:在mysql第一次登录修改了密码后,第二次登录时遇到
解决:mysql> alter user 'root'@'localhost' identified by 'rootadmin';(rootadmin登录密码)

4.问题:ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
描述:在修改密码时,没有设置过期状态为 N
解决:
第一步:修改 /etc/my.cnf 的 mysqld下面添加 skip-grant-tables ,并重启mysql
第二步:登录mysql,并重新设置密码和过期状态
mysql> update user set authentication_string=PASSWORD("vst123456"),password_expired = 'N' where user='root';
第三步:修改 /etc/my.cnf 的 mysqld下面删除 skip-grant-tables ,并重启mysql

5.问题:host 192.168.*.* is not allowed to connect to this mysql server
描述:使用客户端连接mysql时报错
解决:
(1)端口原因,没开放3306端口
# firewall-cmd --state //查看firewall是否启动
# firewall-cmd --zone=public --add-port=3306/tcp --permanent //添加开放端口
# firewall-cmd --reload //重启防火墙

(2)帐号不允许从远程登陆
登录mysql
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>flush privileges;
mysql>select host, user from user;

六.结束

第一次在Centos安装MySQL,遇到很多问题,过程中一些问题分享下,有不足的地方,请指教~~ 一.环境 1.Centos7 全安装(一些...

一、安装准备

安装依赖包

# yum  -y  install  gcc gcc-c++ ncurses ncurses-devel cmake bison

相关依赖包的作用:cmake:由于从 MySQL5.5 版本开始弃用了常规的 configure 编译方法,所以需要 CMake 编译器,用于设置 mysql 的编译参数。如:安装目录、数据存放目录、字符编码、排序规则等。

boost:从 MySQL 5.7.5 开始 Boost 库是必需的,mysql 源码中用到了 C++的 Boost 库,要求必须安装boost1.59.0 或以上版本

gcc:是 Linux 下的 C 语言编译工具,mysql 源码编译完全由 C 和 C++编写,要求必须安装GCC

bison:Linux 下 C/C++语法分析器

ncurses:字符终端处理库

2. 去MySQL官方网站下载MySQL源码安装包,注意,一定要选择下图的源代码版,否则cmake时会报错:

二、下载相应源码包

#  wget  https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

#  wget  https://cdn.mysql.com//archives/mysql-5.7/mysql-5.7.9.tar.gz

 www.9159.com 1

三、新建MySQL用户和用户组

# groupadd  -r  mysql

#  useradd  -r -g  mysql  -s  /sbin/nologin    -M  mysql

  1. 预先安装依赖软件:

    yum install -y gcc-c++ make cmake bison bison-devel ncurses-devel libaio-devel perl perl-Data-Dumper

四、预编译

#  tar  -zxf  boost_1_59_0.tar.gz

#  tar  -zxf  mysql-5.7.11.tar.gz

#  mkdir -p /data/mysql

# cd mysql-5.7.11

# cmake

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

-DMYSQL_DATADIR=/data/mysql 

-DSYSCONFDIR=/etc 

-DMYSQL_USER=mysql

-DWITH_MYISAM_STORAGE_ENGINE=1

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_MEMORY_STORAGE_ENGINE=1

-DWITH_READLINE=1

-DMYSQL_UNIX_ADDR=/tem/mysql.sock 

-DMYSQL_TCP_PORT=3306

-DENABLED_LOCAL_INFILE=1

-DENABLE_DOWNLOADS=1

-DWITH_PARTITION_STORAGE_ENGINE=1

-DEXTRA_CHARSETS=all

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8_general_ci

-DWITH_DEBUG=0

-DMYSQL_MAINTAINER_MODE=0

-DDOWNLOAD_BOOST=1

-DWITH_BOOST=../boost_1_59_0

-DWITH_SSL:STRING=bundled

-DWITH_ZLIB:STRING=bundled

############################################

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql          [MySQL安装的根目录]

-DMYSQL_DATADIR=/data/mysql                         [MySQL数据库文件存放目录]

-DSYSCONFDIR=/etc                    [MySQL配置文件所在目录]

-DMYSQL_USER=mysql                       [MySQL用户名]

-DWITH_MYISAM_STORAGE_ENGINE=1           [MySQL的数据库引擎]

-DWITH_INNOBASE_STORAGE_ENGINE=1          [MySQL的数据库引擎]

-DWITH_ARCHIVE_STORAGE_ENGINE=1           [MySQL的数据库引擎]

-DWITH_MEMORY_STORAGE_ENGINE=1           [MySQL的数据库引擎]

-DWITH_READLINE=1                                                                 [MySQL的readline library]

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock                                      [MySQL的通讯目录]

-DMYSQL_TCP_PORT=3306                      [MySQL的监听端口]

-DENABLED_LOCAL_INFILE=1                      [启用加载本地数据]

-DENABLE_DOWNLOADS=1                   [编译时允许自主下载相关文件]

-DWITH_PARTITION_STORAGE_ENGINE=1

-DEXTRA_CHARSETS=all                        [使MySQL支持所有的扩展字符]

-DDEFAULT_CHARSET=utf8                  [设置默认字符集为utf8]

-DDEFAULT_COLLATION=utf8_general_ci            [设置默认字符校对]

-DWITH_DEBUG=0                      [禁用调试模式]

-DMYSQL_MAINTAINER_MODE=0

-DDOWNLOAD_BOOST=1                   [允许在线更新boost库]

-DWITH_BOOST=../boost_1_59_0                                                 [指定boost安装路径]

-DWITH_SSL:STRING=bundled                [通讯时支持ssl协议]

-DWITH_ZLIB:STRING=bundled                 [允许使用zlib library]

####################################################

 

五、编译安装

#  make -j  `grep processor /proc/cpuinfo | wc -l`

//编译很消耗系统资源,小内存可能编译通不过

# make install

// 花费时间会较长

如果中途编译失败了,需要删除cmake生成的预编译配置参数的缓存文件和make编译后生成的文件,再重新编译。

#  make  clean

# rm -rf  CMakeCache.txt

  1. 创建MySQL用户和用户组
    先查看是否已经创建:

    cat /etc/passwd | grep mysql cat /etc/group | grep mysql

六、更改目录权限

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

# chown  -R  mysql:mysq    l/data/mysql

没有创建则新建mysql用户以及用户组:

七、设置启动脚本,开机自启动

# cp  /usr/local/mysql/support-files/mysql.server    /etc/init.d/mysqld

# vim  /etc/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql

# chmod +x  /etc/init.d/mysqld

# chkconfig    --add  mysqld

# chkconfig mysqld  on

1 groupadd mysql
2 useradd -r -g mysql mysql

八,修改环境变量,添加库文件路径

# vim  /etc/profile

export  PATH=/usr/local/mysql/bin:$PATH

# source /etc/profile

# vim /etc/ld.so.conf

/usr/local/mysql/lib

# ldconfig

 

九、自定义配置文件

/etc/my.cnf,仅供参考

cat > /etc/my.cnf << EOF

[client]

port = 3306

socket= /tmp/mysql.sock

default-character-set = utf8mb4

[mysqld]

port = 3306

socket= /tmp/mysql.sock

basedir = /usr/local/mysql

www.9159.com,datadir = /data/mysql

pid-file= /data/mysql/mysql.pid

user= mysql

bind-address = 0.0.0.0

server-id= 1

init-connect = 'SET NAMES utf8mb4'

character-set-server = utf8mb4

#skip-name-resolve

#skip-networking

back_log = 300

max_connections = 1000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 128

max_allowed_packet = 4M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 8M

key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin

binlog_format = mixed

expire_logs_days = 30

log_error = /data/mysql/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /data/mysql/mysql-slow.log

performance_schema = 0

explicit_defaults_for_timestamp

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB

#default-storage-engine = MyISAM

innodb_file_per_table = 1

innodb_open_files = 500

innodb_buffer_pool_size = 64M

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_thread_concurrency = 0

innodb_purge_threads = 1

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 2M

innodb_log_file_size = 32M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M

myisam_sort_buffer_size = 8M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

interactive_timeout = 28800

wait_timeout = 28800

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

EOF

5. 我把源码包放在了/tmp目录下,解压缩MySQL

十、初始化数据库

# /usr/local/mysql/bin/mysqld  --initialize-insecure  --user=mysql  --basedir=/usr/local/mysql  --datadir=/data/mysq

注:

MySQL之前版本mysql_install_db是在mysql_basedir/script下

MySQL 5.7直接放在了mysql_install_db/bin目录下。

"–initialize"已废弃,生成一个随机密码(~/.mysql_secret)

"--initialize-insecure "不会生成密码

"–datadir"目录下不能有数据文件

tar -zxv -f mysql-5.7.15.tar.gz

十一、启动数据库

# systemctl start mysqld

# systemctl status mysqld

# systemctl enable mysqld

 

十二、查看MySQL服务进程和端口

# netstat  -pantu | grep 3306

# ps  -elf  | grep  mysqld

  1. 创建MySQL安装目录和数据目录

    1 mkdir /usr/local/mysql 2 mkdir /usr/local/mysql/data

十三、设置数据库root用户密码

MySQL和Oracle数据库一样,数据库也默认自带了一个 root 用户(这个和当前Linux主机上的root用户是完全不搭边的),我们在设置好MySQL数据库的安全配置后初始化root用户的密码。配制过程中,一路输入 y 就行了。这里只说明下MySQL5.7版本中,用户密码策略分成低级 LOW 、中等 MEDIUM 和超强 STRONG 三种,推荐使用中等 MEDIUM 级别!

# mysql_secure_installation

 

十四、登录数据路

# mysql  -u root  -h localhost -p

7. 创建boost文件夹并复制boost文件到这个目录中,否则cmake会报错,本示例中使用的是boost_1_59_0.tar.gz

十五、selinux 防火请设置

selinux:

# sed-i"s/SELINUX=enforcing/SELINUX=disabled/"/etc/selinux/config

#setenforce 0

iptables:

# iptables -A INPUT  -m state --state NEW -m tcp  -p tcp --dport 3306 -j ACCEPT

# iptables-save

firewalld:

# firewall-cmd --zone=public --add-port=3306/tcp--permanent

# firewall-cmd --reload

mkdir /usr/local/boost
cp /tmp/boost_1_59_0.tar.gz /usr/local/boost/

 

  1. cmake安装MySQL

    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/boost/boost_1_59_0.tar.gz

 

  1. 安装过程会持续一段时间,耐心等待。

    make && make install

 

  1. 安装完成之后修改/etc/my.cnf

    vim /etc/my.cnf

    [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock

    symbolic-links=0

    skip-grant-tables

    [mysqld_safe] log-error=/usr/local/mysql/logs/mysql.log pid-file=/usr/local/mysql/localhost.localdomain.pid

    !includedir /etc/my.cnf.d    

    mkdir /usr/local/mysql/logs

 

  1. 修改MySQL目录所有者

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

 

12. 添加MySQL服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

 

  1. 启动MySQL

    service mysql start

显示启动成功:Starting MySQL....... SUCCESS!

 

  1. 开启MySQL

    /usr/local/mysql/bin/mysql -uroot -p

  2. 完成!

本文由9159.com发布于www.9159.com,转载请注明出处:安装依赖包,7. 创建boost文件夹并复制boost文件到

关键词:

上一篇:没有了
下一篇:没有了