Centos 7 安装 MySQL 8.0.16

1.01:环境

CentOS Linux 7 (Core)
mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz

1.02:数据库下载地址:

        https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz

1.03:添加用户组和用户:

groupadd mysql
useradd -r -g mysql mysql

1.04:创建数据和日志文件夹:

mkdir -p /data/mysql /logs/mysql /var/lib/mysql /tmp_mysql

1.05:解压mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz 到/usr/local/

xz -d mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
tar xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar -C /usr/local/mysql

1.06:修改mysql相关文件夹权限:

chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /logs/mysql/
chown -R mysql:mysql /var/lib/mysql/
chown -R mysql:mysql /tmp_mysql
chmod -R 777 /usr/local/mysql/
chmod -R 777 /data/mysql/
chmod -R 777 /logs/mysql/
chmod -R 777 /var/lib/mysql/
chmod -R 777 /tmp_mysql

1.07:简单配置my.cnf:

vim /etc/my.cnf

配置如下:

[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/logs/mysql/error.log
port=3306
user=mysql
server-id=3306
symbolic-links=0
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-time-zone='+8:00'

max_connections=1000
max_connect_errors=1000
tmp_table_size=256M
max_heap_table_size=256M

log-bin=/data/mysql/mysql-bin
expire_logs_days=7
tmpdir=/tmp_mysql

# 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]
pid_file=/data/mysqld/mysqld.pid
log_error=/logs/mysql/error.log

#
# include all files from the config directory
#
[client]
socket=/data/mysql/mysql.sock
default-character-set=utf8mb4

!includedir /etc/my.cnf.d

1.08:创建连接:

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump

1.09:初始化数据库:

cd /usr/local/mysql/
./bin/mysqld --defaults-file=/etc/my.cnf --initialize

1.10:启动数据库:

./bin/mysqld --defaults-file=/etc/my.cnf &

1.11:查看临时登录密码:

cat /logs/mysql/error.log | grep password

1.12:修改root密码:

mysql -uroot -p
-- 密码换成123456,可以换成你需要的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; 

1.13:设定root远程访问:

UPDATE mysql.user SET HOST='%' WHERE USER='root';
FLUSH PRIVILEGES;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;

1.14:开放3306端口:

firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload

1.15:增加mysql服务并设置开机启动:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 2345 mysql on

你可能感兴趣的:(运维,centos,mysql)