源码编译安装MySql8.0.22

简介源码编译安装MySql8.0.22

1.准备工作

rpm -qa|grep mariadb 查看是否自带数据库

yum -y remove mariadb* boost-* 卸载自带数据库

检查是否存在mysql用户、用户组,不存在,创建
cat /etc/group  | grep mysql
cat /etc/passwd | grep mysql

groupadd mysql 创建mysql用户组

useradd -g mysql mysql -M -s /sbin/nologin/  创建mysql用户并禁止登陆

删除my.cnf mysql
rm -rf /etc/my.cnf
rpm -qa | grep mysql

2.安装或升级依赖

安装ncurses-devel
yum
-y install ncurses-devel

升级gcc5.3以上版本
http://www.vpser.net/manage/centos-6-upgrade-gcc.html

安装camke3
yum
-y install cmake3


3.下载源码包并解压


官网下载
mysql8.0.22版本
本地下载后使用
xftp上传到服务器即可
或者:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.22.tar.gz
tar -zxvf mysql-boost-8.0.22.tar.gz
cd mysql-boost-8.0.22

4.编译

cmake3
-DCMAKE_INSTALL_PREFIX=
/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DSYSCONFDIR=/etc \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/src/mysql-8.0.22/boost \
-DDOWNLOAD_BOOST=1 \
-DFORCE_INSOURCE_BUILD=1

编译出错情况1CMake Error at cmake/os/Linux.cmake:67 (MESSAGE)
https://blog.csdn.net/weixin_45444133/article/details/105006987
其余各种错误则可根据错误提示百度寻找答案即可

5.安装


make & make install

系统内存小于2g安装过程中可能报错
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
原因是内存不足
sudo dd if=/dev/zero of=/swapfile bs=64M count=16

sudo mkswap /swapfile

sudo swapon /swapfile

用完之后得还回去:
sudo
swapoff /swapfile

sudo rm /swapfile

6.修改mysql目录权限


chown -R mysql:mysql /usr/local/mysql  修改所属组与用户

chmod -R 755 /usr/local/mysql 修改权限

7.初始化mysql初始化成功后会给你一串登录密码,一定先保存下来
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8

8.安装ssl

/usr/local/mysql/bin/mysql_ssl_rsa_setup

9.启动和关闭mysql


/usr/local/mysql/bin/mysqld_safe
--user=mysql &    启动
/usr/local/mysql/bin/mysqladmin -uroot -p shutdown 关闭

10.登录mysql并修改密码


/usr/local/mysql/bin/mysql -u root -p
alter user  root@'localhost' identified by "123456";

11.防火墙中开启3306远程访问

systemctl start firewalld 开启防火墙

firewall-cmd --zone=public --add-port=3306/tcp --permanent 开放3306端口

firewall-cmd --reload 刷新

firewall-cmd --list-ports 查看是否开放3306端口

12.mysql数据库设置远程连接权限

添加远程登陆用户
create user root@'%' identified by '123456';

为远程用户分配权限
grant all privileges on *.* to root@'%';

flush privileges;

查看当前用户,host% 的用户表示远程登陆用户
select user,host from mysql.user;

后面通过Navicat你会发现远程连接不上数据库 提示1251错误
通过百度得知
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123123';(修改密码认证方式为mysql_native_password

13.自定义配置文件启动mysql(可选)


vim /etc/my.cnf
i 编辑模式(输入内容)
esc 退出编辑模式
shift+: 输入命令wq保存退出

自定义配置文件内容
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/usr/local/mysql/tmp/mysqld.sock
# 指定编码 utf8mb4
character-set-server=utf8mb4
# utf8mb4的排序规则
collation-server=utf8mb4_0900_ai_ci
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/log/error.log
pid-file=/usr/local/mysql/log/mysql.pid

[client]
port=3306
socket=/usr/local/mysql/tmp/mysqld.sock


其中的目录(tmp log)和文件(mysqld.sock mysql.pid error.log)创建后并给予mysql用户权限
chown -R mysql:mysql /usr/local/mysql/tmp/
chown -R mysql:mysql /usr/local/mysql/log/
 

文章评论

共有0条评论来说两句吧...

用户名:

验证码:

Top