MYSQL8.0服务部署

1.MySQL8.0环境准备

[root@mysql ~]#curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@mysql ~]#curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@mysql ~]# systemctl is-active firewalld    
unknown
[root@mysql ~]#  systemctl is-enabled firewalld
disabled
[root@mysql ~]# getenforce 
Disabled
[root@mysql ~]#  rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@mysql ~]# yum remove -y mariadb-libs
[root@mysql ~]# yum install -y libaio-devel
[root@xiaoQ-01 ~]# ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5

2.MySQL8.0部署

[root@mysql ~]# cd /usr/local/
[root@mysql /usr/local]# rz -y
[root@mysql /usr/local]# tar xf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
-- 解压数据库服务软件程序压缩包
[root@mysql /usr/local]# ln -s mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz  mysql
-- 创建数据库服务程序目录的软链接
[root@mysql /usr/local]# tail -1 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@mysql /usr/local]# source /etc/profile
-- 配置数据库服务程序环境变量
[root@mysql /usr/local]#  mysql -V
mysql  Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)
-- 可以获取数据库服务版本信息表示环境变量配置生效
[root@mysql /usr/local]# useradd mysql
-- 创建数据库服务管理用户信息
[root@mysql /usr/local]# mkdir -p /data/3306/data /data/3306/logs
[root@mysql /usr/local]# chown -R mysql. /data/
-- 创建数据库服务相关目录并进行目录信息进行授权

3.MySQL初始化

[root@mysql /usr/local]#  mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
2024-11-16T13:45:25.434065Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.32-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.32) initializing of server in progress as process 1789
2024-11-16T13:45:25.440784Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-11-16T13:45:25.705707Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-11-16T13:45:26.179284Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

4.MySQL数据库程序编写配置⽂件

[root@mysql /usr/local]# cat >/etc/my.cnf<<EOF
> [mysql]
> socket=/tmp/mysql.sock
> [mysqld]
> user=mysql
> basedir=/usr/local/mysql
> datadir=/data/3306/data
> socket=/tmp/mysql.sock
> EOF
-- 创建数据库服务相关目录并进行目录信息进行授权

5.在数据库程序⽬录中找到启动脚本⽂件,并将脚本⽂件复制到指定⽬录中

[root@mysql /usr/local]# ls -l /usr/local/mysql/support-files/mysql.server 
-rwxr-xr-x 1 7161 31415 10576 12月 17 2022 /usr/local/mysql/support-files/mysql.server
-- 数据库服务默认的启动脚本文件
[root@mysql /usr/local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
-- 设置数据库服务程序启动运行文件
[root@mysql /usr/local]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/3306/data/mysql.err'.
. SUCCESS! 
-- 启动数据库服务程序利用脚本文件
[root@mysql /usr/local]# chkconfig --add mysqld
-- 设置数据库服务开机自动运行
[root@mysql /usr/local]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
-- 将service管理服务方式转换为systemd管理服务方式
[root@mysql /usr/local]# netstat -lntup|grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      2281/mysqld         
tcp6       0      0 :::33060                :::*                    LISTEN      2281/mysqld        
[root@mysql /usr/local]# ps -ef |grep mysql
root       2581      1  0 22:04 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/3306/data --pid-file=/data/3306/data/mysql.pid
mysql      2722   2581  1 22:04 ?        00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql.err --pid-file=/data/3306/data/mysql.pid --socket=/tmp/mysql.sock
root       2771   1547  0 22:05 pts/0    00:00:00 grep --color=auto mysql
-- 检查确认数据库服务是否启动成功

6.MySQL数据库程序登录访问测试

[root@mysql /usr/local]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ^DBye

7.给MySQL配置登陆密码,并使⽤新密码进⾏登录数据库

[root@mysql /usr/local]#  mysqladmin password '1'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@mysql /usr/local]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ^DBye
posted @ 2024-11-16 22:10  Nolen_H  阅读(25)  评论(0)    收藏  举报