欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

CentOS8部署LNMP环境之编译安装mysql8.0.29的教程详解

程序员文章站 2022-07-09 16:45:26
一、前提由于我安装了几次,我就不再讲述报错了,有点打脑壳!!!提前把相关依赖和报错就地解决。1、所需源码包mysql-8.0.19.tar.gz boost_1_70_0.tar.gz//安装mysq...

一、前提

由于我安装了几次,我就不再讲述报错了,有点打脑壳!!!提前把相关依赖和报错就地解决。

1、所需源码包

mysql-8.0.19.tar.gz 
boost_1_70_0.tar.gz		//安装mysql-8所需要的boost版本
rpcsvc-proto-1.4.tar.gz		//后面出错所需要的源码包

mysql-8.0.19下载地址:http://mirrors.sohu.com/mysql/
boost_1_70_0下载地址:https://dl.bintray.com/boostorg/release/1.70.0/source/
rpcsvc-proto-1.4下载地址:https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/

2、解决依赖

[14:41:21 root@wangzhike ~]#yum install -y cmake ncurses-devel

3、存放位置

软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字

二、编译安装mysql-8.0.19

1、上传源码包

boost_1_70_0.tar.gz		
mysql-8.0.19.tar.gz		
rpcsvc-proto-1.4.tar.gz

CentOS8部署LNMP环境之编译安装mysql8.0.29的教程详解

2、解决rpcsvc-proto-1.4

1)、解压

[17:05:14 root@wangzhike software]#tar -zxf rpcsvc-proto-1.4.tar.gz -c /usr/local/src/

2)、一步安装

[17:09:48 root@wangzhike rpcsvc-proto-1.4]#./configure && make && make install

3、解决boost_1_70_0

[17:13:48 root@wangzhike~]# mkdir -p /usr/local/boost
[17:14:05 root@wangzhike~]# cd /usr/local/src
[17:15:02 root@wangzhike src]#cp /software/boost_1_70_0.tar.gz /usr/local/boost/
[17:26:22 root@wangzhike boost]#tar xf boost_1_70_0.tar.gz
////只上传到/usr/local/src/存放目录,解压到当前boost目录

4、创建mysql用户及组

[17:27:46 root@wangzhike ~]#groupadd mysql
[17:28:10 root@wangzhike ~]#useradd -g mysql mysql -s /bin/false
####创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
[17:28:11 root@wangzhike ~]#mkdir -p /data/mysql 
####创建mysql数据库存放目录
[17:29:13 root@wangzhike ~]#chown -r mysql:mysql /data/mysql 
####设置mysql数据库存放目录权限
[17:29:31 root@wangzhike ~]#mkdir -p /usr/local/mysql 
####创建mysql安装目录

5、安装mysql-8.0.19

1)、解压

[17:43:24 root@wangzhike software]#tar -zxf mysql-8.0.19.tar.gz -c /usr/local/src/
[17:43:47 root@wangzhike software]#cd /usr/local/src/
[17:43:53 root@wangzhike src]#cd mysql-8.0.19/

2)、安装

[17:47:01 root@wangzhike mysql-8.0.19]#cmake . \
-dcmake_install_prefix=/usr/local/mysql \
-dinstall_datadir=/data/mysql -dmysql_user=mysql \
-dmysql_unix_addr=/tmp/mysqld.sock -ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci \
-dwith_innobase_storage_engine=1 \
-dwith_embedded_server=1 \
-dforce_insource_build=1 \
-dwith_myisam_storage_engine=1 \
-denabled_local_infile=1 \
-dextra_charsets=all \
-dwith_boost=/usr/local/boost

若出现以下则没毛病

cmake warning: manually-specified variables were not used by the
project:

extra_charsets
install_datadir
mysql_user
with_embedded_server

– build files have been written to: /usr/local/src/mysql-8.0.19

若出现以下关于rpc.h的错误
could not find rpc/rpc.h in /usr/include or /usr/include/tirpc

解决方法:

[17:45:47 root@wangzhike mysql-8.0.19]#find / -name rpc.h
/usr/local/src/mysql-8.0.19/extra/libevent/include/event2/rpc.h
/usr/local/src/mysql-8.0.19/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/windeps/sunrpc/rpc/rpc.h

####并将/usr/local/src/mysql-8.0.19/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/windeps/sunrpc/目录下的rpc/rpc.h拷贝到/usr/include/

如下

[17:52:57 mysql-8.0.19]#cp -a /usr/local/src/mysql-8.0.19/plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/windeps/sunrpc/rpc /usr/include/

3)、make && install

[17:55:20 mysql-8.0.19]#make -j 3 && install
//过程超长且内存不足的会报错

等待等待等待

若报以下错则表示内存不足需要创建分区

+: fatal error: killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [sql/cmakefiles/sql_gis.dir/build.make:154: sql/cmakefiles/sql_gis.dir/gis/distance_functor.cc.o] error 1
make[2]: *** waiting for unfinished jobs....
make[1]: *** [cmakefiles/makefile2:11144: sql/cmakefiles/sql_gis.dir/all] error 2
make: *** [makefile:163: all] error 2

创建分区:

[19:58:37 root@wangzhike mysql-8.0.19]#dd if=/dev/zero of=/swapfile bs=1k count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 gb, 2.0 gib) copied, 6.07651 s, 345 mb/s
####获取要增加的2g的swap文件块
[20:10:02 root@wangzhike mysql-8.0.19]#mkswap /swapfile
mkswap: /swapfile: insecure permissions 0644, 0600 suggested.
setting up swapspace version 1, size = 2 gib (2097147904 bytes)
no label, uuid=18a4bbb3-75d1-411b-ac0c-c87c63547509
####创建swap文件
[20:10:07 root@wangzhike mysql-8.0.19]#swapon /swapfile
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
####激活swap文件
[20:10:12 root@wangzhike mysql-8.0.19]#swapon -s
filename        type   size used priority
/dev/sda2        partition  2144252 137300 -2
/swapfile        file   2047996 0  -3
#####查看swap信息是否正确
[20:10:19 root@wangzhike mysql-8.0.19]#echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab
####添加到fstab文件中让系统引导时自动启动

在重新执行make -j 3 && make install ,出现以下画面则没有报错

```bash
-- installing: /usr/local/mysql/man/man1/comp_err.1
-- installing: /usr/local/mysql/man/man1/ibd2sdi.1
-- installing: /usr/local/mysql/man/man1/innochecksum.1
-- installing: /usr/local/mysql/man/man1/lz4_decompress.1
-- installing: /usr/local/mysql/man/man1/my_print_defaults.1
-- installing: /usr/local/mysql/man/man1/myisam_ftdump.1
-- installing: /usr/local/mysql/man/man1/myisamchk.1
-- installing: /usr/local/mysql/man/man1/myisamlog.1
-- installing: /usr/local/mysql/man/man1/myisampack.1
-- installing: /usr/local/mysql/man/man1/mysql.1
-- installing: /usr/local/mysql/man/man1/mysql.server.1
-- installing: /usr/local/mysql/man/man1/mysql_config.1
-- installing: /usr/local/mysql/man/man1/mysql_config_editor.1
-- installing: /usr/local/mysql/man/man1/mysql_secure_installation.1
-- installing: /usr/local/mysql/man/man1/mysql_ssl_rsa_setup.1
-- installing: /usr/local/mysql/man/man1/mysql_tzinfo_to_sql.1
-- installing: /usr/local/mysql/man/man1/mysql_upgrade.1
-- installing: /usr/local/mysql/man/man1/mysqladmin.1
-- installing: /usr/local/mysql/man/man1/mysqlbinlog.1
-- installing: /usr/local/mysql/man/man1/mysqlcheck.1
-- installing: /usr/local/mysql/man/man1/mysqld_multi.1
-- installing: /usr/local/mysql/man/man1/mysqld_safe.1
-- installing: /usr/local/mysql/man/man1/mysqldump.1
-- installing: /usr/local/mysql/man/man1/mysqldumpslow.1
-- installing: /usr/local/mysql/man/man1/mysqlimport.1
-- installing: /usr/local/mysql/man/man1/mysqlman.1
-- installing: /usr/local/mysql/man/man1/mysqlpump.1
-- installing: /usr/local/mysql/man/man1/mysqlshow.1
-- installing: /usr/local/mysql/man/man1/mysqlslap.1
-- installing: /usr/local/mysql/man/man1/perror.1
-- installing: /usr/local/mysql/man/man1/zlib_decompress.1
-- installing: /usr/local/mysql/man/man8/mysqld.8
-- installing: /usr/local/mysql/man/man1/mysqlrouter.1
-- installing: /usr/local/mysql/man/man1/mysqlrouter_passwd.1
-- installing: /usr/local/mysql/man/man1/mysqlrouter_plugin_info.1

三、初始化mysql数据库

1、修改mysql目录权限

[20:37:59 root@wangzhike mysql-8.0.19]#chown -r mysql:mysql /usr/local/mysql
[20:42:07 root@wangzhike mysql-8.0.19]#chmod -r 755 /usr/local/mysql

2、初始化mysql

[20:45:07 root@wangzhike ~]#cd /usr/local/mysql/
[20:46:43 root@wangzhike mysql]#./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8
2020-04-14t12:47:13.718724z 0 [system] [my-013169] [server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 9893
2020-04-14t12:47:13.719367z 0 [warning] [my-013242] [server] --character-set-server: 'utf8' is currently an alias for the character set utf8mb3, but will be an alias for utf8mb4 in a future release. please consider using utf8mb4 in order to be unambiguous.
2020-04-14t12:47:14.855541z 5 [note] [my-010454] [server] a temporary password is generated for root@localhost: rug-.8kdw<1f
####生成mysql系统数据库。

3、修改配置文件
mysql 8.0.x默认没有配置文件,我们自己创建一个。

[20:49:41 root@wangzhike mysql]#vi /usr/local/mysql/my.cnf
添加以下内容:
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user = mysql
socket=/tmp/mysql.sock
tmpdir = /tmp
key_buffer_size=16m
max_allowed_packet=128m
default_authentication_plugin=mysql_native_password
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 1
character-set-server = utf8
federated
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
[mysqldump]
quick
[client]
password="123456"
[mysqld-8.0]
sql_mode=traditional
[mysqladmin]
force
[mysqld]
key_buffer_size=16m
service mysqld restart

:wq!保存退出
注意,service mysqld restart 这一句一定写上,默认密码为123456

其他操作

[20:53:05 root@wangzhike mysql]#ln -s /usr/local/mysql/my.cnf /etc/my.cnf
#添加到/etc目录的软连接
[20:53:12 root@wangzhike mysql]#cd
[20:53:13 root@wangzhike ~]#cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
#把mysql加入系统启动
[20:53:21 root@wangzhike ~]#chmod 755 /etc/init.d/mysqld
#增加执行权限
[20:53:28 root@wangzhike ~]#chkconfig mysqld on
#加入开机启动

4、编辑文件

[20:53:39 root@wangzhike ~]#vi /etc/rc.d/init.d/mysqld

####找到basedir=并修改为/usr/local/mysql
####找到datadir=并修改为/data/mysql

basedir=/usr/local/mysql		#mysql程序安装路径
datadir=/data/mysql				#mysql数据库存放目录

5、开机启动成功

[20:54:32 root@wangzhike ~]#service mysqld start
starting mysql.logging to '/data/mysql/wangzhike.err'.
. success!		#启动成功

6、添加变量

[20:54:44 root@wangzhike ~]#vi /etc/profile

在最后一行添加export path=$path:/usr/local/mysql/bin

[20:55:37 root@wangzhike ~]#source /etc/profile			#使配置立刻生效

7、添加软连接

[20:55:44 root@wangzhike ~]#ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[20:55:57 root@wangzhike ~]#ln -s /usr/local/mysql/include/mysql /usr/include/mysql
####以上为把myslq的库文件链接到系统默认的位置

[20:56:02 root@wangzhike ~]#mkdir /var/lib/mysql
[20:56:14 root@wangzhike ~]#ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

8、启动mysql

[21:40:14 root@wangzhike ~]#mysql -uroot -p123456
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 9
server version: 8.0.19 source distribution

copyright (c) 2000, 2020, oracle and/or its affiliates. all rights reserved.

oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql>

则表示登陆成功。

总结

到此这篇关于centos8部署lnmp环境之编译安装mysql-8.0.29的文章就介绍到这了,更多相关centos8部署lnmp环境之编译安装mysql-8.0.29内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!