0.安装依赖

    1. yum install -y numactl

    1.解压

    1. tar -zxvf mysql-8.0.23-linux-glibc2.12-x86_64.tar

    2.移动文件夹

    1. mv mysql-8.0.23 /usr/local/mysql5.7

    3.创建文件夹

    1. mkdir /usr/local/mysql5.7/data
    2. mkdir /var/lib/mysql
    3. mkdir /var/run/mariadb
    4. touch /var/log/mariadb/mariadb.log
    5. mkdir /var/run/mariadb

    4.添加权限

    1. useradd mysql
    2. chgrp mysql /usr/local/mysql5.7
    3. chown mysql /usr/local/mysql5.7
    4. chgrp mysql /var/lib/mysql
    5. chown mysql /var/lib/mysql

    5.修改配置文件

    1. vim /etc/my.cnf
    2. [client]
    3. socket = /var/lib/mysql/mysqld.sock
    4. [mysqld]
    5. #skip_grant_tables
    6. port=3300
    7. character-set-server=utf8
    8. datadir=/usr/local/mysql5.7/data/mysql
    9. basedir=/usr/local/mysql5.7
    10. user=mysql
    11. symbolic-links=0
    12. #socket = /var/lib/mysql/mysqld.sock
    13. # sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    14. group_concat_max_len=204800
    15. lower_case_table_names=1
    16. max_allowed_packet=50M
    17. [mysqld_safe]
    18. character-set-server=utf8

    6.初始化仓库

    1. /usr/local/mysql5.7/bin/mysqld --initialize --user=mysql
    2. ln /var/lib/mysql/mysqld.sock /tmp/mysql.sock

    7.保存初始密码
    8.启动mysql

    1. /usr/local/mysql5.7/bin/mysqld_safe --user=mysql

    9.修改root密码

    1. /usr/local/mysql5.7/bin/mysql -uroot -p
    2. ALTER USER 'root'@'localhost' IDENTIFIED BY 'supplier';
    3. flush privileges;

    10.添加远程访问权限

    1. create user 'root'@'%' IDENTIFIED BY 'supplier';
    2. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' ;
    3. flush privileges;

    11.如果忘记密码
    配置文件添加 配置项,连接数据库修改密码

    1. [mysqld]
    2. skip_grant_tables
    3. /usr/local/mysql5.7/bin/mysql
    4. ALTER USER 'root'@'localhost' IDENTIFIED BY 'supplier';
    5. ALTER USER 'root'@'%' IDENTIFIED BY 'supplier';

    12.数据备份

    1. /usr/local/mysql5.7/bin/mysqldump -uroot -p database > /root/database.sql

    12.数据导入

    1. 1:
    2. /usr/local/mysql5.7/bin/mysql -uroot -p < /root/database.sql
    3. 2:
    4. mysql> create database abc; # 创建数据库
    5. mysql> use abc; # 使用已创建的数据库
    6. mysql> set names utf8; # 设置编码
    7. mysql> source /root/database.sql # 导入备份数据库