ubuntu系统20.04 安装 mysql-5.7.33并实现自动化部署
Posted Linux蛋蛋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu系统20.04 安装 mysql-5.7.33并实现自动化部署相关的知识,希望对你有一定的参考价值。
配置系统环境
系统版本:Ubuntu 20.04.2 LTS
源地址:阿里源
cat /etc/apt/sources.list | grep -v ^# |grep -v ^$
deb http://mirrors.aliyun.com/ubuntu focal main restricted
deb http://mirrors.aliyun.com/ubuntu focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu focal universe
deb http://mirrors.aliyun.com/ubuntu focal-updates universe
deb http://mirrors.aliyun.com/ubuntu focal multiverse
deb http://mirrors.aliyun.com/ubuntu focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu focal-security universe
deb http://mirrors.aliyun.com/ubuntu focal-security multiverse
#更新源
apt update && apt upgrade
开始部署
1.0 下载源码软件包
#官网
https://downloads.mysql.com/archives/community/
#命令行直接下载
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.33.tar.gz
tar -xf mysql-boost-5.7.33.tar.gz && cd mysql-5.7.33
2.0 安装编译环境
apt install -y build-essential cmake bison libncurses5-dev libssl-dev pkg-config
#预编译环境
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \\
-DMYSQL_DATADIR=/usr/local/mysql/data \\
-DWITH_BOOST=boost \\ #指定依赖环境
-DDEFAULT_CHARSET=utf8 \\ #指定字符集
-DDEFAULT_COLLATION=utf8_general_ci \\ #下载所有字符集
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \\
-DFORCE_INSOURCE_BUILD=ON
#开始编译,大概20分钟编译完成
make -j2 && make install
3.0 配置用户文件属性
groupadd mysql
useradd -g mysql mysql
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql/logs/
chown -R mysql:mysql /usr/local/mysql
4.0 初始化系统配置
/usr/local/mysql/bin/mysqld \\
--initialize-insecure \\
--user=mysql \\
--basedir=/usr/local/mysql \\
--datadir=/usr/local/mysql/data
#配置ssl
/usr/local/mysql/bin/mysql_ssl_rsa_setup \\
--user=mysql \\
--basedir=/usr/local/mysql \\
--datadir=/usr/local/mysql/data
#主配置文件
cat /etc/my.cnf
[client]
default-character-set=utf8
socket=/tmp/mysql.sock
[mysqld]
basedir=/usr/local/mysql
port=3306
datadir=/usr/local/mysql/data/
socket=/tmp/mysql.sock
log_error=/usr/local/mysql/logs/error.log
max_connections=2000
default-storage-engine=INNODB
max_allowed_packet=16M
innodb_buffer_pool_size=128M
explicit_defaults_for_timestamp=true
5.0 配置启动服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/support-files/mysql.server /usr/lib/systemd/system/
chmod +x /etc/init.d/mysqld
update-rc.d mysqld defaults
#配置环境变量
echo -e '# MySQL PATH\\nexport PATH=/usr/local/mysql/bin:$PATH\\n' >> /etc/profile
source /etc/profile
#启动服务
systemctl restart mysqld
systemctl enable mysqld
#配置密码
mysql -e "alter user 'root'@'localhost' identified by 'root';"
远程登录配置
mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
mysql>flush privileges;
#验证数据库
mysql -uroot -proot -e "show databases;"
至此 20.4系统源码安装mysql5.7数据库完成
以上是关于ubuntu系统20.04 安装 mysql-5.7.33并实现自动化部署的主要内容,如果未能解决你的问题,请参考以下文章
windows10安装ubuntu20.04双系统详细图文教程,windows10安装ubuntu20.04详细教程