centos7安装mysql8(源码包方式)

安装编译需要的依赖

yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
rpm -qa |grep libaio
yum install libaio libaio-devel

下载源码包

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz

创建用户和组

groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql

创建安装目录和数据存放目录

mkdir -p /usr/local/mysql
mkdir -p /data/mysql

修改权限

chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql
chmod -R 755 /usr/local/mysql/ 
chmod -R 755 /data/mysql/

解压

tar -zxf mysql-boost-8.0.12.tar.gz

下载安装boost,boost的路径要对应下面DWITH_BOOST的路径

mkdir /usr/local/boost
wget http://www.sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.gz
tar -xvzf boost_1_59_0.tar.gz

配置

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mnt/mnt2/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DWITH_BOOST=/usr/local/boost \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

参数说明

CMAKE_INSTALL_PREFIX :指定基础安装目录
MYSQL_DATADIR :指定数据目录
SYSCONFDIR=/etc :指定配置文件扫描目录
MYSQL_TCP_PORT :指定端口号
WITH_BOOST :指定boost所在目录
DEFAULT_CHARSET :指定默认字符集
DEFAULT_COLLATION :指定默认排序规则
ENABLED_LOCAL_INFILE=ON :是否为load data infile启用local
WITH_INNODB_MEMCACHED=ON :是否生成memcached共享库

编译安装

make && make install

初始化数据库

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

创建配置文件

vi /etc/my.cnf

[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
#user=root
#password=123
#数据库大小写不敏感
lower_case_table_names = 1
[mysqld]
server-id=1
#skip-grant-tables
port=3306
user=mysql
max_connections=200
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
pid-file=/data/mysql/mysql.pid
init-connect=‘SET NAMES utf8’
character-set-server=utf8
default-storage-engine=INNODB
log_error=/data/mysql/mysql-error.log
slow_query_log_file=/data/mysql/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=16M

配置环境变量

echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profile

做成系统服务

vi /etc/systemd/system/mysqld.service

[Unit]
Description=mysql server daemon
Documentation=man:mysql(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
LimitNOFILE = 10000
Restart=always
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false

启动MySQL

systemctl start mysqld.service

#修改root密码:使用WITH指定认证方式

mysql -uroot

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘你的密码’;

你可能感兴趣的:(Linux,MySql)