Mysql8.0如何实现源码编译安装
这篇文章主要为大家展示了“MySQL 8.0如何实现源码编译安装”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Mysql 8.0如何实现源码编译安装”这篇文章吧。
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了江干免费建站欢迎大家使用!
一、准备工作
1. 下载安装包
路径:https://dev.mysql.com/downloads/mysql/
这里选择 mysq-8.0.16.tar.gz
2. 清理已有版本
##查询
rpm -qa | grep mysql rpm -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 mysql useradd -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=3306 socket=/data/mysql/3306/mysql.sock [mysqld] port=3306 user=mysql socket=/data/mysql/3306/mysql.sock pid-file=/data/mysql/3306/mysql.pid basedir=/usr/local/mysql datadir=/data/mysql/3306/data tmpdir=/data/mysql/3306/tmp open_files_limit=60000 #explicit_defaults_for_timestamp server-id=3306 lower_case_table_names=1 character-set-server=utf8 #federated #sql_mode=STRICT_TRANS_TABLES max_connections=1000 max_connect_errors=100000 interactive_timeout=86400 wait_timeout=86400 sync_binlog=0 back_log=100 default-storage-engine=InnoDB log_slave_updates=1 #*********** Logs related settings *********** log-bin=/data/mysql/3306/log/mysql3306-bin binlog_format=mixed binlog_cache_size=32m max_binlog_cache_size=64m max_binlog_size=512m long_query_time=1 log_output=FILE log-error=/data/mysql/3306/log/mysql-error.log slow_query_log=1 slow_query_log_file=/data/mysql/3306/log/slow_statement.log #log_queries_not_using_indexes general_log=0 general_log_file=/data/mysql/3306/log/general_statement.log #expire-logs-days = 14 binlog_expire_logs_seconds=1728000 relay-log=/data/mysql/3306/log/relay-bin relay-log-index=/data/mysql/3306/log/relay-bin.index #****** MySQL Replication New Feature********* master-info-repository=TABLE relay-log-info-repository=TABLE #relay-log-recovery #*********** INNODB Specific options *********** innodb_buffer_pool_size=2048M transaction-isolation=REPEATABLE-READ innodb_buffer_pool_instances=8 innodb_file_per_table=1 innodb_data_home_dir=/data/mysql/3306/innodb innodb_data_file_path=ibdata1:2048M:autoextend innodb_thread_concurrency=8 innodb_log_buffer_size=16M innodb_log_file_size=128M innodb_log_files_in_group=3 innodb_log_group_home_dir=/data/mysql/3306/innodb_log innodb_flush_log_at_trx_commit=2 innodb_max_dirty_pages_pct=70 innodb_flush_method=O_DIRECT [mysql] no-auto-rehash default-character-set=gbk prompt = (\u@\h) [\d]>\_
(1)3307
vim /data/mysql/3307/my3307.cnf
内容如下:
[client] port=3307 socket=/data/mysql/3307/mysql.sock [mysqld] port=3307 user=mysql socket=/data/mysql/3307/mysql.sock pid-file=/data/mysql/3307/mysql.pid basedir=/usr/local/mysql datadir=/data/mysql/3307/data tmpdir=/data/mysql/3307/tmp open_files_limit=60000 #explicit_defaults_for_timestamp server-id=3307 lower_case_table_names=1 character-set-server=utf8 #federated #sql_mode=STRICT_TRANS_TABLES max_connections=1000 max_connect_errors=100000 interactive_timeout=86400 wait_timeout=86400 sync_binlog=0 back_log=100 default-storage-engine=InnoDB log_slave_updates=1 #*********** Logs related settings *********** log-bin=/data/mysql/3307/log/mysql3306-bin binlog_format=mixed binlog_cache_size=32m max_binlog_cache_size=64m max_binlog_size=512m long_query_time=1 log_output=FILE log-error=/data/mysql/3307/log/mysql-error.log slow_query_log=1 slow_query_log_file=/data/mysql/3307/log/slow_statement.log #log_queries_not_using_indexes general_log=0 general_log_file=/data/mysql/3307/log/general_statement.log #expire-logs-days = 14 binlog_expire_logs_seconds=1728000 relay-log=/data/mysql/3307/log/relay-bin relay-log-index=/data/mysql/3307/log/relay-bin.index #****** MySQL Replication New Feature********* master-info-repository=TABLE relay-log-info-repository=TABLE #relay-log-recovery #*********** INNODB Specific options *********** innodb_buffer_pool_size=2048M transaction-isolation=REPEATABLE-READ innodb_buffer_pool_instances=8 innodb_file_per_table=1 innodb_data_home_dir=/data/mysql/3307/innodb innodb_data_file_path=ibdata1:2048M:autoextend innodb_thread_concurrency=8 innodb_log_buffer_size=16M innodb_log_file_size=128M innodb_log_files_in_group=3 innodb_log_group_home_dir=/data/mysql/3307/innodb_log innodb_flush_log_at_trx_commit=2 innodb_max_dirty_pages_pct=70 innodb_flush_method=O_DIRECT [mysql] no-auto-rehash default-character-set=gbk prompt = (\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如何实现源码编译安装”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!
当前标题:Mysql8.0如何实现源码编译安装
标题链接:http://azwzsj.com/article/iepgos.html