centos7 编译安装 mysql8
yum -y install gcc gcc++ gcc-c++ wget make libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel bison autoconf cmake bison-devel libaio-devel git ncurses-devel pcre pcre-devel libffi-devel libffi uuid uuid-devel libuuid-devel gperf
wget -c https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
wget -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12.tar.gz
tar -zxvf mysql-8.0.12.tar.gz
mv boost_1_68_0.tar.gz mysql-8.0.12
cd mysql-8.0.12
tar -zxvf boost_1_68_0.tar.gz
mkdir configure
cd configure
cmake .. -DBUILD_CONFIG=mysql_release \
-DINSTALL_LAYOUT=STANDALONE \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_DTRACE=OFF \
-DWITH_EMBEDDED_SERVER=OFF \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-DWITH_PAM=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-8.0.12/ \
-DINSTALL_PLUGINDIR="/usr/local/mysql-8.0.12/lib/plugin" \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EDITLINE=bundled \
-DFEATURE_SET=community \
-DCOMPILATION_COMMENT="MySQL Server (GPL)" \
-DWITH_DEBUG=OFF \
-DWITH_BOOST=../boost_1_68_0/
#如果编译出错 rm -rf CMakeCache.txt 后重新编译
{如果boost的版本不对你也可以下载下面这个boost版本试试通过 -DDOWNLOAD_BOOST=1 -DWITH_BOOST= 来指定路径
wget https://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.gz/download -O boost_1_67_0.tar.gz
}
make & make install
#给mysql 创建用户
useradd -M -s /sbin/nologin mysql #-M 不要自动建立用户的登入目录 -s 用户登入后所使用的shell
mkdir -p /mysql/mysqldata
mkdir -p /var/log/mysql-8.0.12
touch /var/log/mysql-8.0.12/mysql-8.0.12.error.log
touch /var/log/mysql-8.0.12/mysql-8.0.12.error.log0
touch /var/log/mysql-8.0.12/mysql-8.0.12.pid
touch /var/log/mysql-8.0.12/mysql-8.0.12.pid0
chown -R mysql:mysql /var/log/mysql-8.0.12
#始化数据库 执行完后会给你生成一个密码
/usr/local/mysql-8.0.12/bin/mysqld --initialize --user=mysql --datadir=/mysql/mysqldata
vi /etc/my.cnf
[mysqld]
datadir=/mysql/mysqldata
socket=/tmp/mysql.sock
port=3306
user=mysql
basedir=/usr/local/mysql-8.0.12
#symbolic-links为0表示数据库或表不可以存储在my.cnf中指定datadir之外的分区或目录
symbolic-links=0
pid-file=/var/log/mysql-8.0.12/mysql-8.0.12.pid0
log-error=/var/log/mysql-8.0.12/mysql-8.0.12.error.log0
socket=/var/log/mysql-8.0.12/mysql.sock
[mysqld_safe]
log-error=/var/log/mysql-8.0.12/mysql-8.0.12.error.log
pid-file=/var/log/mysql-8.0.12/mysql-8.0.12.pid
#直接启动mysql
/usr/local/mysql-8.0.12/bin/mysqld --defaults-file=/etc/my.cnf &
ln -s /usr/local/mysql-8.0.12/bin/mysql /usr/local/bin/mysql
#这时可以通过mysql -uroot -p 来测试是否可以连接上 密码是之前初始化数据库时生成的密码
#第一次登录进去需要你修改密码,你可以执行下面的命令
alter user 'root'@'localhost' identified by 'nihoa';
#设置启动脚本
cp /usr/local/mysql-8.0.12/support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld #修改其中的三个变量为你实际设置的变量
basedir=/usr/local/mysql-8.0.12
datadir=/mysql/mysqldata
mysqld_pid_file_path=/var/log/mysql-8.0.12/mysql-8.0.12.pid0
#现在可以使用/etc/init.d/mysqld 来启动及停止mysql了
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
©著作权归作者所有:来自51CTO博客作者hello_world007的原创作品,如需转载,请注明出处,否则将追究法律责任