MySQL8.0源码安装
1.二进制安装
1)、创建操作系统用户:
groupadd mysql
useradd -g mysql mysql
2)、解压二进制包,建立软链接
cd /usr/local
tar xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
ln -s mysql-8.0.25-linux-glibc2.12-x86_64 mysql
3)、修改配置文件
vim /etc/my.cnf
[client]
socket=/data/mysql/3306/data/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
socket=/data/mysql/3306/data/mysql.sock
log-error=/data/mysql/3306/data/mysqld.err
port=3306
user=mysql
log_timestamps=system
default_authentication_plugin = mysql_native_password
4)、创建数据目录,并修改其属主、属组。
mkdir -p /data/mysql/3306/data
chown mysql.mysql /data/mysql/3306/data
5)、初始化实例:
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize
6)、启动实例
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
7)、登录实例(使用初始化过程中生成的随机密码)
grep password /data/mysql/3306/data/mysqld.err
[root@pgdb2 ~]# grep password /data/mysql/3306/data/mysqld.err
2023-04-08T21:25:10.426835+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rhgple;-w0jM
mysql -uroot -p’z3vfW786kn;b’;
8)、修改密码
alter user user() identified by ‘123456’;
mysql8.0 设置不同的密码验证策略,具体策略由参数
mysql> install component ‘file://component_validate_password’;
Query OK, 0 rows affected (0.01 sec)
mysql> select * from mysql.component;
±-------------±-------------------±-----------------------------------+
| component_id | component_group_id | component_urn |
±-------------±-------------------±-----------------------------------+
| 1 | 1 | file://component_validate_password |
±-------------±-------------------±-----------------------------------+
1 row in set (0.00 sec)
mysql> show variables like ‘%policy%’;
±-------------------------±-------+
| Variable_name | Value |
±-------------------------±-------+
| validate_password.policy | MEDIUM |
±-------------------------±-------+
1 row in set (0.01 sec)
mysql> alter user user() identified by ‘123456’;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user user() identified by ‘P@ssw0rd’;
Query OK, 0 rows affected (0.00 sec)
2.源码安装
环境清除
1)、使用yum源安装的mysql
yum remove mysql mysql-server mysql-libs compat-mysql51
rm -rf /var/lib/mysql
rm /etc/my.cnf
rm /etc/my.cnf
2)、使用rpm安装的mysql
rpm -qa | grep -i mysql
卸载rpm包
rpm -e mysql-community-server-5.6.51-2.el7.x86_64
rpm -e mysql-community-client-5.6.51-2.el7.x86_64
#编译安装cmake包
yum install -y gcc
tar -zxvf cmake-3.12.1.tar.gz
cd cmake-3.12.1/
./bootstrap --prefix=/usr/local/cmake
make -j 6
make install
vim ~/.bash_aliases
alias cmake=/usr/local/cmake/bin/cmake
source ~/.bash_aliases
cmake -version
1)、安装依赖包,解压源码包
[root@pgdb2 ~]# yum install gcc gcc-c++ glibc ncurses-devel openssl-devel libaio-devel
cd /usr/local
tar xvf mysql-boost-8.0.25.tar.gz
cd /usr/local/mysql-8.0.25/
mkdir build
cd /usr/local/mysql-8.0.25/build
配置编译文件
cmake /usr/local/mysql-8.0.25/ -DWITH_BOOST=/usr/local/mysql-8.0.25/boost/boost_1_73_0 -DENABLE_DOWNLOADS=1 -DBUILD_CONFIG=mysql_release
编译安装
make -j 6 && make install
报错1:
Could not find devtoolset compiler in /opt/rh/devtoolset-10
Please set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly.
yum install centos-release-scl
yum install devtoolset-10-gcc devtoolset-10-gcc-c++
报错2:
g++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [sql/CMakeFiles/sql_gis.dir/gis/difference.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs…
make[1]: *** [sql/CMakeFiles/sql_gis.dir/all] Error 2
make: *** [all] Error 2
解决方法:创建一个swap分区
dd if=/dev/zero of=/tmp/swapfile bs=1M count=4096
mkswap /tmp/swapfile
swapon /tmp/swapfile
安装完后,其他步骤同二进制安装
配置文件的读取顺序
cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --verbose --help|grep -A1 “Default options”
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
配置MYSQL环境变量
echo “PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH” >> /etc/profile
echo “export PATH” >> /etc/profile
source /etc/profile
验证MySQL登录是否成功:
[root@localhost bin]#mysql -uroot -p’P@ssw0rd’;
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.25 Source distribution
Copyright © 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered 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>
查看参数的来源、修改时间、修改用户等。
mysql> select * from performance_schema.variables_info where variable_name=‘max_connections’\G;
*************************** 1. row ***************************
VARIABLE_NAME: max_connections
VARIABLE_SOURCE: COMPILED
VARIABLE_PATH:
MIN_VALUE: 1
MAX_VALUE: 100000
SET_TIME: NULL
SET_USER: NULL
SET_HOST: NULL
1 row in set (0.00 sec)
设置systemctl 启动mysqld方式:
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(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
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false