Centos7 离线安装 mysql8(亲自尝试过)

2023-12-15 18:12:49


1)解压安装

/usr/local目录下

①??? wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz

②??? tar -Jxvf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz

③??? mv mysql-8.0.27-linux-glibc2.12-x86_64 mysql

2)? 创建用户,用户组

groupadd mysql

useradd -r -g mysql mysql

3) 创建数据目录

mkdir -p /data/mysql8_data

# 更改属主和数组
chown -R mysql:mysql /data/mysql8_data
# 更改模式
chmod -R 777 /data/mysql8_data


4) 添加配置文件

vim /etc/my.cnf

[mysql]
default-character-set=utf8mb4
[client]
port?????? = 16033
socket???? = /tmp/mysql.sock
[mysqld]
port?????? = 16033
server-id? = 16033
user?????? = mysql
socket???? = /tmp/mysql.sock

basedir??? = /usr/local/mysql

datadir??? = /data/mysql8_data/mysql
log-bin??? = /data/mysql8_data/mysql/mysql-bin
innodb_data_home_dir????? =/data/mysql8_data/mysql
innodb_log_group_home_dir =/data/mysql8_data/mysql

log-error =/data/mysql8_data/mysql/mysql.log
pid-file? =/data/mysql8_data/mysql/mysql.pid

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
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


5) 初始化??? --lower-case-table-names=1 为忽略数据库表名大小写


cd /usr/local/mysql/bin/
?? ?
./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql8_data/mysql/ --user=mysql --initialize-insecure --lower-case-table-names=1


6) 启动MySQL


①添加mysql服务到系统

?????? cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

②授权以及添加服务

?????? chmod +x /etc/init.d/mysql
?????? chkconfig --add mysql

③将mysql命令添加到服务

?????? ln -s /usr/local/mysql/bin/mysql /usr/bin

④启动

????? service mysql start

????? service mysql status

????? service mysql stop

????? service mysql restart
?
?⑤确认是否启动

ps -ef|grep mysql

7) 登录MySQL

# 首次无密码
mysql -u root --skip-password

1.1 修改密码

# 首次设置密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'BJ2023&';
# 刷新权限
FLUSH PRIVILEGES;

# 平时修改密码
SET PASSWORD FOR '用户名'@'主机' = PASSWORD(‘密码');
# 刷新权限
FLUSH PRIVILEGES;

1.2 建立远程连接

# 选择 mysql 数据库
use mysql;
# 查看当前用户
SELECT user,host,plugin,authentication_string FROM user;
# 创建无IP限制用户
CREATE user 'root'@'%';
# 设置首次密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'BJ2023&';
# 授权用户所有权限,刷新权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;

8)开放16033端口


# 查看防火墙状态:systemctl status firewalld ?
# 查看端口状态:no 表示未开启
firewall-cmd --query-port=16033/tcp
# 永久开放端口:
firewall-cmd --add-port=16033/tcp --permanent
# 重启防火墙:
systemctl restart firewalld


参考:

https://zhuanlan.zhihu.com/p/631562715

https://blog.csdn.net/weixin_42198656/article/details/121250817


https://blog.csdn.net/qq_40634846/article/details/110749132

一. 问题背景

??? 在新买的阿里云服务器上面安装MySQL8,然而在初始化MySQL的时候报错了,报错详情是./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory。

二. 解决方案

因为可能是新的服务器环境,上面很多依赖都没有,所以安装软件的时候遇到一大堆小问题,解决它很简单,它缺少啥就安装啥。

我们使用如下命令:

yum install -y libaio.so.1

如果执行了上面的命令仍无法解决,那么执行如下:

yum install -y libaio

文章来源:https://blog.csdn.net/y19910825/article/details/135018089
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。