安装版本
Rocky 8.5 Mysql 8.0.28
检查是否已安装
rpm -qa | grep mysql
下载安装包
若无wget命令,使用yum安装下
yum -y list wget
yum -y install wget.x86_64
下载
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar
移动到/usr/local目录
mv mysql-8.0.28-linux-glibc2.12-x86_64.tar /usr/local
解压到安装目录,创建binlog、存储目录
tar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar
继续解压mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
得到解压后的目录,重命名下
mv mysql-8.0.28-linux-glibc2.12-x86_64 mysql
创建binlog和库文件的存储目录 mkdir -p /usr/local/mysql/binlog /appdata/data_mysql
创建mysql用户组、用户,赋权给mysql目录
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/ /appdata/data_mysql
编译安装初始化
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/appdata/data_mysql --basedir=/usr/local/mysql --lower_case_table_names=1
注:lower_case_table_names 在初始化时才能设置 记下root用户的临时密码,后面用于登录
创建my.cnf配置文件
cd /etc/
vi my.cnf
添加以下内容
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set=UTF8MB4
[mysqld]
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
lower_case_table_names=1
character_set_server=UTF8MB4
innodb_file_per_table=1
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /appdata/data_mysql
log-error = /usr/local/mysql/mysql_error.log
#pid-file = /usr/local/mysql/mysql.pid
open_files_limit = 65535
back_log = 600
max_connections = 5000
max_connect_errors = 1000
table_open_cache = 1024
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 600
#thread_concurrency = 8
#query_cache_size = 128M
#query_cache_limit = 2M
#query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default-tmp-storage-engine=MYISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 128M
max_heap_table_size = 128M
log-slave-updates
log-bin = /usr/local/mysql/binlog/binlog
binlog-do-db=oa_fb
binlog-ignore-db=mysql
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /usr/local/mysql/relaylog/relaylog
#relay-log-info-file = /usr/local/mysql/relaylog/relaylog
relay-log = /usr/local/mysql/relaylog/relaylog
expire_logs_days = 10
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
#myisam_recover
interactive_timeout = 120
wait_timeout = 120
#skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host = 192.168.1.2
#master-user = username
#master-password = password
#master-port = 3306
server-id = 1
slow_query_log_file=/usr/local/mysql/mysql_slow.log
long_query_time = 1
[mysqldump]
quick
max_allowed_packet = 32M
启动服务,并添加自启动
添加软连接
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
切换mysql用户,启动
su mysql
service mysqld start
如果启动失败,可能是开启了selinux Starting MySQL… ERROR! The server quit without updating PID file (/appdata/data_mysql/master.pid). 添加selinux 安全标签解决此问题。参考:selinux mysql_MySQL的selinux配置
chcon -R -t mysqld_db_t /storage/db/
启动成功 添加服务
chkconfig --add mysqld
登录并重置密码,开放远程链接
登录数据库
/usr/local/mysql/bin/mysql -u mysql -p
有如下报错 root用户执行如下命令解决,参考:mysql 报 error while loading shared libraries: libtinfo.so.5 解决办法
ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
继续登录,然后又报错Access denied for user ‘mysql’@‘localhost’ (using password: YES) 参考博客链接的方式解决,跳过密码登录,重置密码后再正常启动登录
先执行
flush privileges;
重置密码
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
创建新用户并授权:
grant all privileges on *.* to mysqldev@'%' identified by '123456' with grant option;
create user mysqldev@'%' identified by '123456';
grant all privileges on *.* to mysqldev@'%' with grant option;
flush privileges;
alter user mysqldev@'%' identified with mysql_native_password by '123456';
开放端口
开放防火墙3306端口,参考博客 远程连接成功
|