编译安装mysql

  1. 编译安装
    [root@mysql1 ~]# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make

cmake:
[root@mysql1 ~]# yum -y install cmake

boost:
[root@mysql1 ~]# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

mysql:
[root@mysql1 ~]# groupadd mysql
[root@mysql1 ~]# useradd -r -g mysql -s /bin/false mysql
[root@mysql1 ~]# tar xvf mysql-5.7.19.tar.gz
[root@mysql1 ~]# cd mysql-5.7.19
[root@mysql3 mysql-5.7.19]# pwd
/root/mysql-5.7.19
[root@mysql3 mysql-5.7.19]# tar xf /root/boost_1_59_0.tar.gz
[[email protected] ~]# cmake .
-DWITH_BOOST=boost_1_59_0/
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DSYSCONFDIR=/etc
-DMYSQL_DATADIR=/usr/local/mysql/data
-DINSTALL_MANDIR=/usr/share/man
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8
-DEXTRA_CHARSETS=all
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_EMBEDDED_SERVER=1
-DENABLED_LOCAL_INFILE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1

提示:boost也可以使用如下指令自动下载
-DDOWNLOAD_BOOST=1

[root@mysql1 ~]# make
[root@mysql1 ~]# make install

  1. 初始化
    [root@mysql1 local]# cd mysql
    [root@mysql1 mysql]# mkdir mysql-files
    [root@mysql1 mysql]# chown -R mysql.mysql .
    [root@mysql1 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    [root@mysql1 mysql]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

建立MySQL配置文件my.cnf
[root@mysql1 mysql]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

启动MySQL
方法二:使用centos6 mysql.server脚本(system V)
[root@mysql1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mysql1 mysql]# chkconfig --add mysqld
[root@mysql1 mysql]# chkconfig mysqld on
[root@mysql1 mysql]# service mysqld start

[root@mysql2 mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql2.err'.
SUCCESS!
[root@mysql2 mysql]# ps aux |grep mysqld
mysql 76 pts/0 Sl 14:38 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql2.err --pid-file=/usr/local/mysql/data/mysql2.pid

PATH[可选]
[root@mysql2 mysql]# mysql
-bash: mysql: command not found
[root@mysql2 mysql]# /usr/local/mysql/bin/mysql
[root@mysql1 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@mysql1 mysql]# source /etc/profile
[root@mysql1 mysql]# mysqladmin -uroot -p'>>e4KKcol6i1' password '(TianYunYang123)'

如果需要重新初始化...[可选]
[root@mysql1 ~]# killall mysqld
[root@mysql1 ~]# rm -rf /usr/local/mysql/data
[root@mysql1 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@mysql1 mysql]# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

你可能感兴趣的:(编译安装mysql)