mysql部署(5.7.31)

下载地址:
MySQL :: Download MySQL Community Server (Archived Versions)

因为系统是Kylin Linux Server V10,底层是centos7,所以选择下面版本

一、删除原来安装的mysql

1.查询并删除

root@localhost /\]# find / -name mysql find: '/run/user/1000/gvfs': Permission denied /etc/selinux/targeted/active/modules/100/mysql /var/lib/mysql /usr/lib64/mysql /usr/share/mysql /usr/local/mysql /usr/local/mysql/bin/mysql /usr/local/mysql/include/mysql /home/etlbat/app/mysql \[root@localhost /\]# rm -rf /etc/selinux/targeted/active/modules/100/mysqlbin/mysql /usr/local/mysql/include/mysql /home/etlbat/app/mysql \[root@localhost /\]# find / -name mysql find: '/run/user/1000/gvfs': Permission denied **2.删除配置文件** 2.1删除mysql的配置文件(my.cnf文件) \[root@localhost /\]# rm -rf /etc/my.cnf 2.2删除 /etc/init.d/ 下跟mysql有关的全部文件 \[root@localhost /\]# cd /etc/init.d/ \[root@localhost init.d\]# ll total 52 -rw-r--r--. 1 root root 18281 May 22 2020 functions -rwxrwxrwx. 1 root root 10614 Dec 4 03:20 mysqld -rwxr-xr-x. 1 root root 4569 May 22 2020 netconsole -rwxr-xr-x. 1 root root 7928 May 22 2020 network -rw-r--r--. 1 root root 1160 Oct 1 2020 README \[root@localhost init.d\]# rm mysqld rm: remove regular file 'mysqld'? y \[root@localhost init.d\]# ls functions netconsole network README **3. 删除mysql的用户和组** \[root@localhost init.d\]# userdel mysql #### 二、安装步骤 **1.进入mysql的安装目录,将文件导入并改名** \[root@localhost init.d\]# cd /usr/local \[root@localhost local\]# ll total 4 drwxr-xr-x. 2 root root 6 Apr 10 2018 bin drwxr-xr-x. 2 root root 6 Apr 10 2018 etc drwxr-xr-x. 2 root root 6 Apr 10 2018 games drwxr-xr-x. 2 root root 6 Apr 10 2018 include drwxr-xr-x. 2 root root 6 Apr 10 2018 lib drwxr-xr-x. 2 root root 6 Apr 10 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 10 2018 libexec -rw-r--r--. 1 root root 103 Dec 4 03:15 mysql-5.7.31 drwxr-xr-x. 2 root root 6 Apr 10 2018 sbin drwxr-xr-x. 5 root root 49 Dec 1 09:51 share drwxr-xr-x. 2 root root 6 Apr 10 2018 src \[root@localhost local\]# tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar \[root@localhost local\]# mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql **2.添加用户组mysql和用户mysql,并将其添加到mysql用户组中** \[root@localhost local\]# groupadd mysql \[root@localhost local\]# useradd -r -g mysql mysql **3.检查是否安装了 libaio** \[root@localhost local\]# rpm -qa \| grep libaio libaio-0.3.109-13.el7.x86_64 **4.配置my.cnf文件** \[root@localhost local\]# vim /etc/my.cnf 将下面内容拷进去 \[mysql

设置mysql客户端默认字符集

default-character-set=utf8

socket=/tmp/mysql.sock

mysqld

#skip-name-resolve

#设置3306端口

port=3306

socket=/tmp/mysql.sock

server-id=1

#开启binlog

log-bin=mysql-bin

binlog_format=ROW

binlog_row_image = full

log_bin = ON

expire_logs_days = 7

设置mysql的真正的安装目录 (看自己的是在哪里)

basedir=/usr/local/mysql

设置mysql数据库的数据的存放目录 (看自己的是在哪里)

datadir=/usr/local/mysql/data

允许最大连接数

max_connections=2000

服务端使用的字符集默认为8比特编码的latin1字符雿

character-set-server=utf8

创建新表时将使用的默认存储引擿

default-storage-engine=INNODB

#lower_case_table_name=1

非必要

max_allowed_packet=16M

join_buffer_size = 128M

sort_buffer_size = 16M

read_rnd_buffer_size = 16M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

max_allowed_packet = 500000M

5.创建data文件夹(就是my.cnf中datadir 所指定的文件夹)

root@localhost local\]# cd mysql \[root@localhost mysql\]# ls bin docs include lib LICENSE man README share support-files \[root@localhost mysql\]# mkdir data **6.将mysql目录的所属用户和组改为mysql,初始化mysqld 生成初始化密码(注意文件地址)** \[root@localhost mysql\]# chown -R mysql:mysql ./ \[root@localhost mysql\]# chmod -R 755 /usr/local/mysql/data \[root@localhost mysql\]# sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2023-12-04T11:50:47.994782Z 0 \[Warning\] option 'max_allowed_packet': unsi 2023-12-04T11:50:47.994844Z 0 \[Warning\] TIMESTAMP with implicit DEFAULT vtion for more details). 2023-12-04T11:50:47.994855Z 0 \[Warning\] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE'ged with strict mode in a future release. 2023-12-04T11:50:47.994856Z 0 \[Warning\] 'NO_AUTO_CREATE_USER' sql mode wa 2023-12-04T11:50:49.094965Z 0 \[Warning\] InnoDB: New log files created, LS 2023-12-04T11:50:49.242651Z 0 \[Warning\] InnoDB: Creating foreign key cons 2023-12-04T11:50:49.302669Z 0 \[Warning\] No existing UUID has been found, UUID: 5e32a105-929b-11ee-b448-000c293b73a1. 2023-12-04T11:50:49.304806Z 0 \[Warning\] Gtid table is not ready to be use 2023-12-04T11:50:49.850871Z 0 \[Warning\] CA certificate ca.pem is self sig 2023-12-04T11:50:49.954514Z 1 \[Note\] A temporary password is generated fo **7.mysql配置** 7.1 设置开机启动,复制mysql.server脚本到资源目录,并赋予执行权限,将 mysqld 服务加入到系统服务并检测是否生效: \[root@localhost mysql\]# cp ./support-files/mysql.server /etc/rc.d/init.d/ \[root@localhost mysql\]# chmod +x /etc/rc.d/init.d/mysql.server \[root@localhost mysql\]# chkconfig --add mysql.server \[root@localhost mysql\]# chkconfig --list mysql.server Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by na systemd configuration. If you want to list systemd services use 'systemctl list-unit-files To see services enabled on particular target use 'systemctl list-dependencies \[target\]'. mysql.server 0:off 1:off 2:on 3:on 4:on 5:on 6:off 7.2启动mysql \[root@localhost mysql\]# service mysql.server start Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.er SUCCESS! **8.配置环境变量** 8.1 在 /etc/profile配置文件中,添加如下内容: \[root@localhost mysql\]# vim /etc/profile #mysql环境变量 PATH=$PATH:/usr/local/mysql/bin \[root@localhost mysql\]# source /etc/profile 8.2 校验是否成功: \[root@localhost mysql\]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/sbal/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/usr/local/mysq **9.初次登录 修改访问密码** \[root@localhost mysql\]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \\g. Your MySQL connection id is 2 Server version: 5.7.31 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserv 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 state mysql\> SET PASSWORD = PASSWORD('password'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql\> **10.配置远程连接,重启mysql** mysql\> grant all privileges on \*.\* to root@"%" identified by "password" with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) 如果报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 执行如下命令修改密码 mysql\> alter user 'root'@'localhost' identified by 'xxx'; mysql\> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql\> \[1\]+ Stopped mysql -u root -p \[root@localhost bin\]# service mysql restart Redirecting to /bin/systemctl restart mysql.service

相关推荐
技术宝哥2 小时前
Redis(2):Redis + Lua为什么可以实现原子性
数据库·redis·lua
学地理的小胖砸3 小时前
【Python 操作 MySQL 数据库】
数据库·python·mysql
dddaidai1234 小时前
Redis解析
数据库·redis·缓存
数据库幼崽4 小时前
MySQL 8.0 OCP 1Z0-908 121-130题
数据库·mysql·ocp
Amctwd4 小时前
【SQL】如何在 SQL 中统计结构化字符串的特征频率
数据库·sql
betazhou5 小时前
基于Linux环境实现Oracle goldengate远程抽取MySQL同步数据到MySQL
linux·数据库·mysql·oracle·ogg
lyrhhhhhhhh5 小时前
Spring 框架 JDBC 模板技术详解
java·数据库·spring
喝醉的小喵6 小时前
【mysql】并发 Insert 的死锁问题 第二弹
数据库·后端·mysql·死锁
付出不多7 小时前
Linux——mysql主从复制与读写分离
数据库·mysql
初次见面我叫泰隆7 小时前
MySQL——1、数据库基础
数据库·adb