openEuler 环境源码编译mysql 8.0.37

部分参考博客 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
sudo 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=~/mysql-8.0.37/boost/boost_1_77_0
sudo make -j 64
sudo make install -j 64

4、在~/上建立mysql.sh

#添加mysql用户
useradd mysql
#修改mysql的密码
passwd mysql

#修改/etc/my.cnf的属主和属组

sudo chown mysql:mysql /etc/mysql/my.cnf
#修改/data目录及其子目录的属主和属组
sudo chown -R mysql:mysql /data
#修改mysql启动脚本的权限
sudo chmod 777 /usr/local/mysql/support-files/mysql.server
#将mysql启动文件复制到/etc/init.d/目录中
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
#设置mysql开机自启动
sudo chkconfig mysql on
#修改mysql启动脚本的属主和属组
sudo chown -R mysql:mysql /etc/init.d/mysql
#将MySQL配置到环境变量中
sudo echo export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile
#执行环境变量,让mysql环境变量生效
source /etc/profile
#mysql数据库初始化
sudo 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服务

sudo /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 -p -S /data/mysql/run/mysql.sock

做成编译脚本的话则如下

MYSQL_CONFIG_FILE="/etc/mysql/my.cnf"


#解压并编译
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=~/mysql-8.0.37/boost/boost_1_77_0/
make -j 64
make install -j 64


sudo rm -rf /data/mysql/data

sudo mkdir /data/mysql/data

#添加mysql用户
useradd mysql
#修改mysql的密码
passwd mysql
#编写mysql配置文件(/etc/my.cnf)

cat <<EOF > $MYSQL_CONFIG_FILE
[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

innodb_data_file_path = ibdata1:12M:autoextend

# You can innodb_buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 2G
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_force_recovery =0

EOF


#修改/etc/my.cnf的属主和属组

sudo chown mysql:mysql /etc/mysql/my.cnf
#修改/data目录及其子目录的属主和属组
sudo chown -R mysql:mysql /data
#修改mysql启动脚本的权限
sudo chmod 777 /usr/local/mysql/support-files/mysql.server
#将mysql启动文件复制到/etc/init.d/目录中
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
#设置mysql开机自启动
sudo chkconfig mysql on
#修改mysql启动脚本的属主和属组
sudo chown -R mysql:mysql /etc/init.d/mysql
#将MySQL配置到环境变量中
sudo echo export PATH=$PATH:/usr/local/mysql/bin >> /etc/profile
#执行环境变量,让mysql环境变量生效
source /etc/profile


#mysql数据库初始化
echo "Initializing Mysql data directory..."
sudo /usr/local/mysql/bin/mysqld  --defaults-file=$MYSQL_CONFIG_FILE --initialize

#启动数据库
echo "Starting Mysql  service..."
sudo /usr/local/mysql/bin/mysqld --defaults-file=/etc/mysql/my.cnf &

#确认mysql运行
sleep 5
if pgrep -x "mysql" > /dev/null
then
    echo "Mysql service started successfully."
else
    echo "Mysql service failed to start."
fi
posted @ 2024-07-17 02:15  拾墨、  阅读(44)  评论(0编辑  收藏  举报