mysql部署-源码、rpm
从源码部署
1、环境装备
1)下载安装包
官网:https://downloads.mysql.com/archives/community/
2)下载依赖环境
yum -y install epel-release cmake bison ncurses-devel openssl-devel
yum -y groupinstall "Development Tools"
3)创建用户、目录
useradd -s /sbin/nologin mysql
mkdir -p /mysql/{mysql,data,conf,logs,tmp}
2、进行编译安装
cd /opt/mysql-5.7.33/
cmake -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_CHARSET=utf8 -DCMAKE_INSTALL_PREFIX=/mysql/mysql \ 安装路径
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=boost
make -j 4 make install
3、编辑配置文件
vim /mysql/conf/mysql.conf
[mysqld]
port = 13306
user = mysql
basedir = /mysql
datadir = /mysql/mysql/data
pid-file = /mysql/mysql.pid
log_error = /mysql/mysql/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /mysql/mysql/logs/mysql-slow.log
# session memory configure.
read_buffer_size = 8M
read_rnd_buffer_size = 4M
sort_buffer_size = 4M
tmp_table_size = 32M
max_heap_table_size = 32M
join_buffer_size = 4M
thread_cache_size = 64
#innodb engine configure.
innodb_file_per_table = 1
innodb_buffer_pool_size = 5G
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_log_file_size = 2G
innodb_log_buffer_size = 32M
innodb_sort_buffer_size = 64M
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_online_alter_log_max_size = 4G
innodb_open_files = 65535
explicit_defaults_for_timestamp=true
4、初始化mysql
1)设置属主属组
chown -R mysql:mysql /data
2)执行初始化指令
/mysql/mysql/bin/mysqld --defaults-file=/mysql/conf/mysql.cnf --initialize-insecure
5、设置mysql环境变量
vim /etc/profile
在最后添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile 使环境变量生效
6、编辑使用systemctl控制mysql
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
ExecStart=/mysql/mysql/bin/mysqld --defaults-file=/mysql/conf/mysql.cnf
systemctl daemon-reload 配置服务生效
7、启动并登录mysql
1)启动mysql
systemctl enable --now mysqld 启动mysql并设置开机自启
2)登录mysql
mysql -uroot
注意:如果报错,执行ln -s /mysql/tmp/mysql.sock /tmp/mysql.sock 设置一个符号链接
mysql> alter user root@localhost identified by "123Abc.."; 第一次登录后在数据库内修改root密码
mysql源码安装脚本下载:
https://opszzfwordpress.club/zb_users/upload/2022/05/mysql_install.sh
rpm部署
1、下载安装包
地址:https://downloads.mysql.com/archives/community/
tar -xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C mysql_rpm/
查看解压文件:
2、进行安装
使用yum的方式进行安装所有解压出的rpm文件:
yum -y install mysql-community-*
启动数据库:
systemctl start mysqld
3、登录数据库
查看数据库初始密码
cat /var/log/mysqld.log | grep -i 'password'
登录数据库
mysql -uroot -p'Xvq-dMHQ#1!F'
在数据库内修改密码
mysql> alter user root@localhost identified by "123Abc..";
mysql源码自动安装脚本:将以下脚本复制到mysql源码文件的目录中,执行mysql_install:
更多系统、中间件、应用、数据库相关脚本:https://opszzfwordpress.club/post/38.html