mysql编译安装

2016/09/12 mysql

Configuration summary

  • using system PCRE library
  • OpenSSL library is not used
  • md5: using system crypto library
  • sha1: using system crypto library
  • using system zlib library

nginx path prefix: “/usr/local/nginx” nginx binary file: “/usr/local/nginx/sbin/nginx” nginx configuration prefix: “/usr/local/nginx/conf” nginx configuration file: “/usr/local/nginx/conf/nginx.conf” nginx pid file: “/usr/local/nginx/logs/nginx.pid” nginx error log file: “/usr/local/nginx/logs/error.log” nginx http access log file: “/usr/local/nginx/logs/access.log” nginx http client request body temporary files: “client_body_temp” nginx http proxy temporary files: “proxy_temp” nginx http fastcgi temporary files: “fastcgi_temp” nginx http uwsgi temporary files: “uwsgi_temp” nginx http scgi temporary files: “scgi_temp”

MYSQL安装

============ 1、下载cmake yum install -y cmake gcc-c++ ncurses-devel bison perl libaio git perl-Data-Dumper yum install gcc-c++ -y yum install ncurses-devel -y yum install bison -y yum install -y perl yum install -y perl-Data-Dumper yum install libaio -y yum install -y git

2、下载安装包 解压 http://dev.mysql.com/downloads/mysql/ http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.10.tar.gz http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz

tar -zxvf mysql-5.5.14.tar.gz cd mysql-5.5.14

   cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/data/mysql/data -DSYSCONFDIR=/etc 需要boost cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/mysql-5.7.10/include/

cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci

============= DENABLED_LOCAL_INFILE:允许导入文件到数据库,以加快数据导入速度, 使用 SQL 语句: LOAD DATA LOCAL INFILE 数据文件 INTO TABLE 表名。

DWITH_READLINE:绑定 readline 的终端快捷键及历史记录功能。但是安装完后是不是仍然找不着 readline 的感觉, 因为 DWITH_READLINE 在 MySQL 5.6.5 版本就被移除了,同样 DWITH_LIBEDIT 在 MySQL 5.6.12 版本也被移除了。

================= 更多编译参数 https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

make && make install

如果编译失败,清理源码目录下的 CMakeCache.txt 文件,重新编译即可。 To prevent old object files or configuration information from being used, run these commands on Unix before re-running CMake: shell> make clean shell> rm -rf CMakeCache.txt

================OK

使用下面的命令查看是否有mysql用户及用户组 cat /etc/passwd 查看用户列表 cat /etc/group 查看用户组列表 如果没有就创建 groupadd mysql useradd -g mysql mysql useradd -r -g mysql -s /bin/false mysql

修改/usr/local/mysql权限 chown -R mysql:mysql /usr/local/mysql

创建日志目录和 SOCK 目录并更改权限

mkdir /var/log/mysql

chown -R mysql:mysql /var/log/mysql/

mkdir /var/lib/mysql/mysql.sock

chown -R mysql:mysql /var/lib/mysql/mysql.sock

复制配置文件

   cp support-files/my-medium.cnf /usr/local/mysql/my.cnf

======================== 初始化配置 http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html

进入安装路径 cd /usr/local/mysql 进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表 // scripts/mysql_install_db –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –user=mysql

scripts/mysql_install_db –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –user=mysql –ldata=/var/lib/mysql

shell> bin/mysql_install_db –user=mysql # Before MySQL 5.7.6 shell> bin/mysqld –initialize –user=mysql # MySQL 5.7.6 and up shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf”,在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。 bin/mysql -uroot -pUe.k3w64aQcs

========

启动MySQL

添加服务,拷贝服务脚本到init.d目录,并设置开机启动 cp support-files/mysql.server /etc/init.d/mysql chkconfig mysql on service mysql start –启动MySQL

========

解决:env: /etc/init.d/mysql:权限不够,遇到了这么一个问题:

env: /etc/init.d/mysqld: 权限不够

解决此问题的办法如下:

chmod a+wrx /etc/init.d/mysqld

然后再次执行:

service mysqld start

启动 MySQL 服务

service mysql56 start

Starting MySQL (Percona Server).. SUCCESS! 更改 root 用户密码 /usr/local/mysql/bin目录

./mysqladmin -poldpassword password newpassword;

./bin/mysqladmin -u root password ‘new-password’

SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘new_password’);

停止 mysqladmin -u root -p shutdown

移动目录的时候,要cp -r /usr/mysql/data移动过去

同时修改目录权限chown -R mysql:mysql newdatadir

常见问题

如果启动 MySQL 服务时出现:Starting MySQL. ERROR! The server quit without updating PID file 错误, 请检查 my.cnf 中 log-error 配置的路径及权限。

如果访问数据库时出现:Can’t connect to local MySQL server through socket ‘xxx.sock’ 错误, 请检查 my.cnf 中 socket 配置的路径及权限。

  配置开机自启动

   cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
   chmod +x /etc/init.d/mysql
   chkconfig --list
   //update-rc.d mysql defaults  (/sbin/chkconfig --add mysql ; /sbin/chkconfig mysql on)
  chkconfig --add mysql 
  chkconfig mysql on
   chkconfig --list mysql

MySQL Installation Layout for Generic Unix/Linux Binary Package

Directory Contents of Directory bin, scripts mysqld server, client and utility programs data Log files, databases docs MySQL manual in Info format man Unix manual pages include Include (header) files lib Libraries share Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

To install and use a MySQL binary distribution, the command sequence looks like this:

shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql shell> cd /usr/local shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> mkdir mysql-files shell> chmod 750 mysql-files shell> chown -R mysql . shell> chgrp -R mysql . shell> bin/mysql_install_db –user=mysql # Before MySQL 5.7.6 shell> bin/mysqld –initialize –user=mysql # MySQL 5.7.6 and up shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up shell> chown -R root . shell> chown -R mysql data mysql-files shell> bin/mysqld_safe –user=mysql &

Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server


Search

    Table of Contents