MySQL8.0安装部署

Posted handsomeboy-东

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL8.0安装部署相关的知识,希望对你有一定的参考价值。

文章目录


解压软件包

cd /usr/local & mkdir mysql
cd mysql    
# 将mysql安装包放在该目录下,安装包在文档最下面
tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.32-linux-glibc2.12-x86_64 mysql8.0 
cd mysql8.0

创建mysql用户,赋予目录权限,修改环境变量

mkdir data
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
chmod 750 /usr/local/mysql/mysql-8.0/data -R
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/mysql-8.0/bin:/usr/local/mysql/mysql-8.0/lib
source /etc/profile

编写配置文件

cat > /etc/my.cnf << EOF
[mysql]
default-character-set=utf8mb4
[client]
#port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld]
#port=3306
#server-id=3306
user=mysql
general_log = 1
general_log_file= /var/log/mysql/mysql.log
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql/mysql-8.0
datadir=/usr/local/mysql/mysql-8.0/data
log-bin=/usr/local/mysql/mysql-8.0/data/mysql-bin
innodb_data_home_dir=/usr/local/mysql/mysql-8.0/data
innodb_log_group_home_dir=/usr/local/mysql/mysql-8.0/data/
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
default_authentication_plugin=mysql_native_password
symbolic-links=0
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/usr/local/mysql/mysql-8.0/data/mysql.log
pid-file=/usr/local/mysql/mysql-8.0/data/mysql.pid

#
# include all files from the config directory
EOF

初始化数据库

cd /usr/local/mysql/mysql-8.0/bin
./mysqld --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql//mysql-8.0/data/ --initialize
fF%hk,jfg0eO   # 记住这个初始登录密码

复制 mysql.server 文件,在/usr/local/mysql/mysql-8.0目录下执行

cp -a ./support-files/mysql.server /etc/init.d/mysql 
cp -a ./support-files/mysql.server /etc/init.d/mysqld

赋权

chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/mysqld

mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/ 

启动mysql,修改root密码

mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
flush privileges;

修改远程登录连接

create user 'root'@'%' identified by  '远程连接密码';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;

软件安装包
链接:https://dev.mysql.com/downloads/mysql/

以上是关于MySQL8.0安装部署的主要内容,如果未能解决你的问题,请参考以下文章

MySQL8.0数据库安装

Linux部署mysql8.0

mysql8.0 安装

mysql8.0.20安装测试innodb cluster

mysql8.0.20安装测试innodb cluster

生产环境mysql安装规划及调优实践--mysql8.0.29为例