CentOS8系统MySQL8二进制安装

解压MySQL安装包:

tar xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql
sudo mv mysql /opt/
cd /opt

安装MySQL:

sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
cd /opt/mysql
sudo mkdir mysql-files
sudo chown mysql:mysql mysql-files
sudo chmod 750 mysql-files
sudo mkdir /opt/mysql/data
sudo chown -R mysql:mysql /opt/mysql/data
sudo mkdir /opt/mysql/log
sudo touch /opt/mysql/log/mysqld.log
sudo chown -R mysql:mysql /opt/mysql/log
sudo bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data

配置环境变量:

sudo vi /etc/profile.d/mysql.sh

添加以下内容:

export PATH=$PATH:/opt/mysql/bin

使命令立即生效:

source /etc/profile

启动MySQL:

sudo bin/mysqld_safe --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --log-error=/opt/mysql/log/mysqld.log --pid-file=/opt/mysql/data/mysql.pid &

设置密码

sudo bin/mysql -u root --skip-password

设置Root密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'dream7788';

新增数据库:

CREATE DATABASE dev CHARSET utf8mb4;

创建用户并授权:

CREATE USER 'nan'@'%' IDENTIFIED BY 'nanjun';
GRANT ALL ON dev.* TO 'nan'@'%';
FLUSH PRIVILEGES;

开放端口

sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --reload

设置开机启动

sudo cp support-files/mysql.server /etc/init.d/mysql
sudo chmod +x /etc/init.d/mysql
sudo chkconfig --add mysql

编写my.cnf,添加以下内容:

[mysqld]
user=mysql
port=3306
key_buffer_size=16M
max_allowed_packet=128M

basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/opt/mysql/data/mysql.sock
log-error=/opt/mysql/log/mysqld.log
pid-file=/opt/mysql/data/mysql.pid

[mysql.server]

basedir=/opt/mysql datadir=/opt/mysql/data pid-file=/opt/mysql/data/mysql.pid

重启MySQL:

sudo systemctl restart mysql

未经允许不得转载:君子如兰 » CentOS8系统MySQL8二进制安装

赞 (0)