千家信息网

Mysql 8.0如何实现源码编译安装

发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,这篇文章主要为大家展示了"Mysql 8.0如何实现源码编译安装",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Mysql 8.0如何实现源码编译安装"这篇
千家信息网最后更新 2025年01月22日Mysql 8.0如何实现源码编译安装

这篇文章主要为大家展示了"Mysql 8.0如何实现源码编译安装",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"Mysql 8.0如何实现源码编译安装"这篇文章吧。

一、准备工作

1. 下载安装包

路径:https://dev.mysql.com/downloads/mysql/

这里选择 mysq-8.0.16.tar.gz

2. 清理已有版本

##查询

rpm -qa | grep mysqlrpm -qa | grep maria

##清理(如果存在的话)

yum remove mysql

##或者

yum remove mariadb

3. 安装依赖包

(1)常规依赖

yum -y install gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel

(2)特殊版本的依赖

编译的时候,分别错误提示:

CMake 3.4.3 or higher is required.

GCC 5.3 or newer is required

所以需要安装Cmake和GCC的相关版本

请参考: http://blog.itpub.net/69915315/viewspace-2648182

二、编译安装(软件)

1. 解压安装包

tar -zxvf tar -zxvf mysql-8.0.16.tar.gz

2. cmake配置

(1) 进入目录 mysql-8.0.16 ,建立一个目录,用于存放编译好的软件

  cd mysql-8.0.16  mkdir xiaochong

(2) 进入子目录xiaochong,进行编译前的配置。 主要cmake后是 . . , 执行其父目录。

   cd  xiaochong

配置参数:

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DENABLED_LOCAL_INFILE=ON \-DWITH_INNODB_MEMCACHED=ON \-DWITH_SSL=system \-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 \-DCOMPILATION_COMMENT="xiaochong edition" \-DDOWNLOAD_BOOST=1 \-DWITH_BOOST=/usr/local/boost \-DCMAKE_CXX_COMPILER=/usr/bin/g++ \-DWITH_BOOST=/tmp

3. 编译

make -j 10

4 . 安装

make install

末尾如下提示,表示成功。

-- Configuring done

-- Generating done

-- Build files have been written to: /software/mysql-8.0.16/xiaochong

--------------------------------------------------------------------------------------------------

错误1 c++: error: unrecognized command line option '-std=c++14'

解决方式: 添加: -DCMAKE_CXX_COMPILER=/usr/bin/g++

三、创建数据库

1、创建用户

groupadd mysqluseradd -g mysql mysql

2. 创建相关目录

mkdir -p /data/mysql/{3306,3307}/{data,log,tmp,innodb,innodb_log}

这里是两个实例的目录,分别是3306和3307.

创建后,目录结构如下:

[root@mysql80 /]# cd data

[mysql@mysql80 data]$ tree .

.

└── mysql

├── 3306

│ ├── data

│ ├── innodb

│ ├── innodb_log

│ ├── log

│ └── tmp

└── 3307

├── data

├── innodb

├── innodb_log

├── log

└── tmp

3. 修改目录权限

chown -R mysql:mysql /data/mysql/chown -R mysql:mysql /usr/local/mysql/

4. 添加环境变量

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

5. 添加配置文件

(1)3306

vim /data/mysql/3306/my3306.cnf

内容如下:

[client]port=3306socket=/data/mysql/3306/mysql.sock[mysqld]port=3306user=mysqlsocket=/data/mysql/3306/mysql.sockpid-file=/data/mysql/3306/mysql.pidbasedir=/usr/local/mysqldatadir=/data/mysql/3306/datatmpdir=/data/mysql/3306/tmpopen_files_limit=60000#explicit_defaults_for_timestampserver-id=3306lower_case_table_names=1character-set-server=utf8#federated#sql_mode=STRICT_TRANS_TABLESmax_connections=1000max_connect_errors=100000interactive_timeout=86400wait_timeout=86400sync_binlog=0back_log=100default-storage-engine=InnoDBlog_slave_updates=1#*********** Logs related settings ***********log-bin=/data/mysql/3306/log/mysql3306-binbinlog_format=mixedbinlog_cache_size=32mmax_binlog_cache_size=64mmax_binlog_size=512mlong_query_time=1log_output=FILElog-error=/data/mysql/3306/log/mysql-error.logslow_query_log=1slow_query_log_file=/data/mysql/3306/log/slow_statement.log#log_queries_not_using_indexesgeneral_log=0general_log_file=/data/mysql/3306/log/general_statement.log#expire-logs-days = 14binlog_expire_logs_seconds=1728000relay-log=/data/mysql/3306/log/relay-binrelay-log-index=/data/mysql/3306/log/relay-bin.index#****** MySQL Replication New Feature*********master-info-repository=TABLErelay-log-info-repository=TABLE#relay-log-recovery#*********** INNODB Specific options ***********innodb_buffer_pool_size=2048Mtransaction-isolation=REPEATABLE-READinnodb_buffer_pool_instances=8innodb_file_per_table=1innodb_data_home_dir=/data/mysql/3306/innodbinnodb_data_file_path=ibdata1:2048M:autoextendinnodb_thread_concurrency=8innodb_log_buffer_size=16Minnodb_log_file_size=128Minnodb_log_files_in_group=3innodb_log_group_home_dir=/data/mysql/3306/innodb_loginnodb_flush_log_at_trx_commit=2innodb_max_dirty_pages_pct=70innodb_flush_method=O_DIRECT[mysql]no-auto-rehashdefault-character-set=gbkprompt = (\u@\h) [\d]>\_

(1)3307

vim /data/mysql/3307/my3307.cnf

内容如下:

[client]port=3307socket=/data/mysql/3307/mysql.sock[mysqld]port=3307user=mysqlsocket=/data/mysql/3307/mysql.sockpid-file=/data/mysql/3307/mysql.pidbasedir=/usr/local/mysqldatadir=/data/mysql/3307/datatmpdir=/data/mysql/3307/tmpopen_files_limit=60000#explicit_defaults_for_timestampserver-id=3307lower_case_table_names=1character-set-server=utf8#federated#sql_mode=STRICT_TRANS_TABLESmax_connections=1000max_connect_errors=100000interactive_timeout=86400wait_timeout=86400sync_binlog=0back_log=100default-storage-engine=InnoDBlog_slave_updates=1#*********** Logs related settings ***********log-bin=/data/mysql/3307/log/mysql3306-binbinlog_format=mixedbinlog_cache_size=32mmax_binlog_cache_size=64mmax_binlog_size=512mlong_query_time=1log_output=FILElog-error=/data/mysql/3307/log/mysql-error.logslow_query_log=1slow_query_log_file=/data/mysql/3307/log/slow_statement.log#log_queries_not_using_indexesgeneral_log=0general_log_file=/data/mysql/3307/log/general_statement.log#expire-logs-days = 14binlog_expire_logs_seconds=1728000relay-log=/data/mysql/3307/log/relay-binrelay-log-index=/data/mysql/3307/log/relay-bin.index#****** MySQL Replication New Feature*********master-info-repository=TABLErelay-log-info-repository=TABLE#relay-log-recovery#*********** INNODB Specific options ***********innodb_buffer_pool_size=2048Mtransaction-isolation=REPEATABLE-READinnodb_buffer_pool_instances=8innodb_file_per_table=1innodb_data_home_dir=/data/mysql/3307/innodbinnodb_data_file_path=ibdata1:2048M:autoextendinnodb_thread_concurrency=8innodb_log_buffer_size=16Minnodb_log_file_size=128Minnodb_log_files_in_group=3innodb_log_group_home_dir=/data/mysql/3307/innodb_loginnodb_flush_log_at_trx_commit=2innodb_max_dirty_pages_pct=70innodb_flush_method=O_DIRECT[mysql]no-auto-rehashdefault-character-set=gbkprompt = (\u@\h) [\d]>\_

6、初始化数据库

(1) 3306

mysqld --defaults-file=/data/mysql/3306/my3306.cnf --initialize --user=mysql

(2) 3307

mysqld --defaults-file=/data/mysql/3307/my3307.cnf --initialize --user=mysql

错误如下:

[mysql@mysql80 ~]$ mysqld --defaults-file=/data/mysql/3306/my.cnf --initialize --user=mysql

mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by mysqld)

mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by mysqld)

mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by mysqld)

mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by mysqld)

解析办法:

原因: 由于我们之前升级了gcc,也就是gcc-5.3.0. 但目录 /lib64/ 下的库文件链接的是 libstdc++.so.6 依然软链接是低版本 libstdc++.so.6.0.19

[root@mysql80 /]# cd /lib64/

[root@mysql80 lib64]# ls -l | grep libstdc++.so.6

lrwxrwxrwx. 1 root root 19 Jun 19 14:36 libstdc++.so.6 -> libstdc++.so.6.0.19

-rwxr-xr-x. 1 root root 991616 Apr 24 22:24 libstdc++.so.6.0.19

进入到新安装的gcc-5.3.0的目录,进入lib64,查看libstdc++.so.6,软链接的是 libstdc++.so.6.0.21

[root@mysql80 gcc-5.3.0]# cd lib64/

[root@mysql80 lib64]# ls -l | grep libstdc++.so.6

lrwxrwxrwx. 1 root root 19 Jun 25 15:54 libstdc++.so -> libstdc++.so.6.0.21

lrwxrwxrwx. 1 root root 19 Jun 25 15:54 libstdc++.so.6 -> libstdc++.so.6.0.21

-rwxr-xr-x. 1 root root 11089328 Jun 25 15:54 libstdc++.so.6.0.21

处理: 删除原来的软链接,建立新的软链接:

[root@mysql80 lib64]# rm -rf libstdc++.so.6

[root@mysql80 lib64]# ln -s /usr/local/gcc-5.3.0/lib64/libstdc++.so.6 libstdc++.so.6

[root@mysql80 lib64]# ls -l | grep libstdc++.so.6

lrwxrwxrwx. 1 root root 41 Jun 26 14:48 libstdc++.so.6 -> /usr/local/gcc-5.3.0/lib64/libstdc++.so.6

7.启动服务

(1) 3306

/mysqld_safe --defaults-file=/data/mysql/3306/my.cnf --user=mysql &

(2)3307

/mysqld_safe --defaults-file=/data/mysql/3307/my.cnf --user=mysql &

8.登录数据库

这里以3306实例为例,3307步骤相同,只需要注意端口号即可,即大写的 -P

(1)查找root@localhost的初始密码,

查看当前错误日志

more /data/mysql/3306/log/mysql-error.log

找到如下行,标红的即是密码:

[MY-010454] [Server] A temporary password is generated for root@localhost: ?/ihz.ew8SIy

mysql -uroot -p'?/ihz.ew8SIy' -P3306 -S /data/mysql/3306/mysql.sock

(2)登录

mysql -uroot -p'?/ihz.ew8SIy' -P3306 -S /data/mysql/3306/mysql.sock

(3)修改密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH sha256_password BY 'Yxc@3306' PASSWORD EXPIRE INTERVAL 360 DAY;

(4) 查询数据库

ysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

9. 校验后台进程

以上是"Mysql 8.0如何实现源码编译安装"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0