部分参考博客 https://blog.csdn.net/ghpanxt/article/details/119387253
1、安装依赖:yum install -y openssl-devel ncurses-devel libaio libaio-devel libtirpc-devel openldap-devel openldap git bison
【注意】:对于openEuler操作系统,还需要安装rpcsvc-proto依赖,具体如下:
wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
tar xzvf rpcsvc-proto-1.4.tar.gz
cd rpcsvc-proto-1.4
./configure
make
make install
2、下载MySQL8.0.37源码,链接地址:
https://downloads.mysql.com/archives/community/
3、解压源码并编译:
tar xzvf mysql-boost-8.0.37.tar.gz
cd ~mysql-8.0.37
mkdir build
cd build
mkdir -p /data/mysql/{data,log,run,tmp}
cmake .. -DBUILD_CONFIG=mysql_release -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DWITH_BOOST=~/boost_1_77_0
make -j 8
make install -j 8
4、在~/上建立mysql.sh
#添加mysql用户
useradd mysql
#修改mysql的密码
passwd mysql#修改/etc/my.cnf的属主和属组chown mysql:mysql /etc/mysql/my.cnf
#修改/data目录及其子目录的属主和属组
chown -R mysql:mysql /data
#修改mysql启动脚本的权限
chmod 777 /usr/local/mysql/support-files/mysql.server
#将mysql启动文件复制到/etc/init.d/目录中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
#设置mysql开机自启动
chkconfig mysql on
#修改mysql启动脚本的属主和属组
chown -R mysql:mysql /etc/init.d/mysql
#将MySQL配置到环境变量中
echo export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile
#执行环境变量,让mysql环境变量生效
source /etc/profile
#mysql数据库初始化
mysqld --defaults-file=/etc/mysql/my.cnf --initialize
5、 修改/etc/mysql/my.cnf
[mysqld_safe]
log-error=/data/mysql/log/mysql.log
pid-file=/data/mysql/run/mysqld.pid[mysqldump]
quick[mysql]
no-auto-rehash[client]
port = 3309
socket = /data/mysql/run/mysql.sock[mysqld]
basedir=/usr/local/mysql
socket=/data/mysql/run/mysql.sock
tmpdir=/data/mysql/tmp
datadir=/data/mysql/data
default_authentication_plugin=mysql_native_password
port=3309
user=mysql
【注意】:需要记录mysql初始密码
6、运行mysql.sh
./mysql.sh
7、启动mysql服务
/usr/local/mysql/bin/mysqld --defaults-file=/etc/mysql/my.cnf &
8、进入mysql
mysql -uroot -p -S /data/mysql/run/mysql.sock#修改root密码
alter user 'root'@'localhost' identified by "open12!@";
#更新权限
flush privileges;
#退出mysql
exit;
#重新进入mysql,验证密码是否修改成功
mysql -uroot -p123456 -S /data/mysql/run/mysql.sock