Linux安装MySQL8源码包|二进制

最近在使用Java实现Linux数据库的备份,但由于自己下载的是mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz,所以只能离线安装,但是网上的教程都不能够解决问题,要么重要的地方出现问题,要么Linux缺少重要文件。所以记录一下自己踩过的坑,希望能够帮助也同样踩坑的朋友(linux注意联网,可能有些系统缺少lib库,需要联网下载)

到官方下载mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz源码包,注意是-linux-glibc即可。将下载好的软件通过xshell上传到Linux中,这里上传的路径是/usr/local/ 解压
tar -Jxf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz之后 再次输入
mv mysql-8.0.28-linux-glibc2.12-x86_64 mysql 方便后续操作
在/etc/profile添加PATH=$PATH:/usr/local/mysql/bin环境变量,source /etc/profile 刷新配置文件,就是MySQL的解压目录,一般都叫安装目录。
完成之后创建用户组,当然如果只是自己使用,可以不用创建直接使用root用户也可以

[root@localhost mysql]# mkdir /usr/local/mysql/data
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql mysql
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql/data
[root@localhost /]# chmod -R 750 /usr/local/mysql/data/

进入mysql目录,创建my.cnf文件

[root@localhost local]#cd mysql
[root@localhost mysql]# mkdir etc
[root@localhost mysql]# cd etc
[root@localhost etc]# vim my.cnf
[root@localhost etc]# chown -R mysql:mysql my.cnf

my.cnf配置文件

[mysql]
# 默认字符集
default-character-set=utf8mb4
[client]
port       = 3306
socket     = /tmp/mysql.sock

[mysqld]
port       = 3306
server-id  = 3306
user       = mysql
socket     = /tmp/mysql.sock
# 安装目录
basedir    = /usr/local/mysql8
# 数据存放目录
datadir    = /usr/local/mysql/data/mysql
log-bin    =/usr/local/mysql/data/mysql-bin
innodb_data_home_dir      =/usr/local/mysql/data/mysql
innodb_log_group_home_dir =/usr/local/mysql/data/mysql
#日志及进程数据的存放目录
log-error =/usr/local/mysql/data/mysql.log
pid-file  =/usr/local/mysql/data/mysql.pid
# 服务端使用的字符集默认为8比特编码
character-set-server=utf8mb4
lower_case_table_names=1
autocommit =1
 
##################以上要修改的########################
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
 
#query_cache_size = 128M
tmp_table_size = 128M
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
 
binlog_format=mixed
 
binlog_expire_logs_seconds =864000
 
# 创建新表时将使用的默认存储引擎
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
transaction-isolation=READ-COMMITTED
 
[mysqldump]
quick
max_allowed_packet = 16M
 
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
 
[mysqlhotcopy]
interactive-timeout

初始化mysql

mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql8_data/mysql --user=mysql --initialize-insecure
#注意自己的路径即可

后台启动

/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf &
#登录数据库
[root@localhost bin]# mysql -uroot -p

可能会报错

mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

这里的意思是缺少libtinfo.so.5依赖文件
输入下面命令自动下载

[root@localhost bin]# sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

到这里就安装成功了mysql --version mysql Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)检测MySQL版本

mysql -u root --skip-password
#跳过密码登录
alter user 'root'@'localhost' identified with mysql_native_password by 'xc123456';
#修改密码

参考文章CentOS7源码包安装mysql8


版权声明:本文为qq_44804223原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。