遇到问题:
之前想在线上搭建mysql5.7.20版本找了很多文档都觉得写得不怎么完善,很多需要注意的错误点都提及,所以只好自己写一篇了!个人觉得最主要注意的是mysql的data目录一定不能漏了权限问题,还有的经常遇到mysql.sock文件的错误就是因为编译的时候指定的目录要小心,然后启动前在my.cnf文件里面定义一下问题就解决了。这是我写的时候遇到最多的问题。
一、进入mysql官网下载(www.mysql.org)mysql源安装包:
按照以下步骤点击:
DOWNLOADS à Communità MySQL Community Server àSelectOperating System: Source Code àSelect OSVersion: (Red Hat Enterprise)
##最后找到mysql-boost-5.7.20.tar.gz文件下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz
二、解压安装步骤:
1、安装编译环境需要的依赖包:
yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel autoconf* automake* zlib* libxml*ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bisonbison-devel perl-Data-Dumper boost boost-doc boost-devel
2、下载源代码和解压源代码:
[root@cml5 ~]#cd /usr/local/src/ [root@cml5src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz [root@cml5src]# tar -zxvf mysql-boost-5.7.20.tar.gz
3、创建mysql用户和data目录:
[root@cml5src]# cd mysql-5.7.20/ [root@cml5mysql-5.7.20]# useradd -M -s /sbin/nologin mysql [root@cml5 mysql-5.7.20]# mkdir -pv /usr/local/mysql/mydata [root@cml5 mysql-5.7.20]# mkdir -pv /usr/local/mysql/conf [root@cml5 mysql-5.7.20]# chown -R mysql /usr/local/mysql [root@cml5 mysql-5.7.20]# rm -rf /etc/my.cnf
##必须删除my.cnf配置文件,这是mariadb的配置文件与mysql文件有冲突。
4、编译安装:
##编译的参数意思:
cmake
-DCMAKE_INSTALL_PREFIX= [MySQL安装的根目录]
-DMYSQL_DATADIR= [MySQL数据库文件存放目录]
-DSYSCONFDIR= [MySQL配置文件所在目录]
-DMYSQL_USER= [MySQL用户名]
-DWITH_MYISAM_STORAGE_ENGINE= [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE= [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE= [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE= [MySQL的数据库引擎]
-DWITH_READLINE= [MySQL的readlinelibrary]
-DMYSQL_UNIX_ADDR= [MySQL的通讯目录]
-DMYSQL_TCP_PORT=[MySQL的监听端口]
-DENABLED_LOCAL_INFILE= [启用加载本地数据]
-DENABLE_DOWNLOADS=[编译时允许自主下载相关文件]
-DWITH_PARTITION_STORAGE_ENGINE=
-DEXTRA_CHARSETS= [使MySQL支持所有的扩展字符]
-DDEFAULT_CHARSET=[设置默认字符集为utf8]
-DDEFAULT_COLLATION= [设置默认字符校对]
-DWITH_DEBUG= [禁用调试模式]
-DMYSQL_MAINTAINER_MODE=
-DWITH_SSL:STRING= [通讯时支持ssl协议]
-DWITH_ZLIB:STRING= [允许使用zlib library]
-DDOWNLOAD_BOOST= [允许在线更新boost库]
-DWITH_BOOST=[指定boost安装路径]
[root@cml5mysql-5.7.20]# cmake >-DCMAKE_INSTALL_PREFIX=/usr/local/mysql >-DMYSQL_DATADIR=/usr/local/mysql/mydata >-DSYSCONFDIR=/usr/local/mysql/conf >-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=/usr/local/mysql/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 >-DWITH_SSL:STRING=bundled >-DWITH_ZLIB:STRING=bundled >-DDOWNLOAD_BOOST=1 >-DWITH_BOOST=./boost
[root@cml5mysql-5.7.20]# make && make install
##这步骤比较久!
5、设置权限和设置添加到系统服务(systemctl管理)
[root@cml5mysql-5.7.20]# cd /usr/local/mysql/ [root@cml5mysql]# ll total 80 drwxr-xr-x 2 mysql root 4096 Nov 7 00:10 bin drwxr-xr-x 2 mysql mysql 6 Nov 6 22:44 conf -rw-r--r-- 1 mysql root 17987 Sep 13 23:48 COPYING -rw-r--r-- 1 mysql root 17987 Sep 13 23:48 COPYING-test drwxr-xr-x 2 mysql root 52 Nov 7 00:00 docs drwxr-xr-x 3 mysql root 4096 Nov 7 00:00 include drwxr-xr-x 4 mysql root 4096 Nov 7 00:00 lib drwxr-xr-x 4 mysql root 28 Nov 7 00:00 man -rw-r--r-- 1 root root 42 Nov 7 08:52 my.cnf drwxr-xr-x 8 mysql mysql 4096 Nov 7 16:38 mydata srwxrwxrwx 1 mysql mysql 0 Nov 7 16:21 mysql.sock -rw------- 1 mysql mysql 6 Nov 7 16:21 mysql.sock.lock drwxr-xr-x 10mysql root 4096 Nov 7 00:00 mysql-test -rw-r--r-- 1 mysql root 2478 Sep 13 23:48 README -rw-r--r-- 1 mysql root 2478 Sep 13 23:48 README-test drwxr-xr-x 28mysql root 4096 Nov 7 00:00 share drwxr-xr-x 2 mysql root 86 Nov 7 00:00 support-files
[root@cml5 mysql]#cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@cml5 mysql]#chmod +x /etc/init.d/mysqld
##设置开机启动:
[root@cml5 mysql]# chkconfig--add mysqld [root@cml5 mysql]# chkconfig mysqld on
6、添加bin目录下的mysql工具到/usr/bin下
[root@cml5 mysql]# cp /usr/local/mysql/bin/* /usr/bin/mysql
7.初始化mysql
[root@cml5 mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql--basedir=/usr/local/mysql --datadir=/usr/local/mysql/mydata
8、创建一个my.cnf文件:
[root@cml5mysql]# cat /etc/my.cnf [mysqld] datadir=/usr/local/mysql/mydata socket=/usr/local/mysql/mysql.sock log_bin=/usr/local/mysql/mydata/mysql-bin server-id=1
My.cnf启动顺序:
? /etc/my.cnf
? /etc/mysql/my.cnf
? /usr/local/mysql/etc/my.cnf
? ~/.my.cnf
? 其他自定义路径下的my.cnf,例如:/data/mysql/yejr_3306/my.cnf
##重设密码:
(之前的博客里面写了,这里就不写了,访问以下地址就ok啦)
http://legehappy.blog.51cto.com/13251607/1979492
9、访问mysql
[root@cml5mysql]# mysql -uroot -p Enterpassword: Welcome to theMySQL monitor. Commands end with ; or\g. Your MySQLconnection id is 11 Serverversion: 5.7.20-log Source distribution Copyright (c)2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is aregistered 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>
本文出自 “第一个legehappy51cto博客” 博客,请务必保留此出处http://legehappy.blog.51cto.com/13251607/1979729
原文地址:http://legehappy.blog.51cto.com/13251607/1979729