0.安装依赖
yum install -y numactl
1.解压
tar -zxvf mysql-8.0.23-linux-glibc2.12-x86_64.tar
2.移动文件夹
mv mysql-8.0.23 /usr/local/mysql5.7
3.创建文件夹
mkdir /usr/local/mysql5.7/data
mkdir /var/lib/mysql
mkdir /var/run/mariadb
touch /var/log/mariadb/mariadb.log
mkdir /var/run/mariadb
4.添加权限
useradd mysql
chgrp mysql /usr/local/mysql5.7
chown mysql /usr/local/mysql5.7
chgrp mysql /var/lib/mysql
chown mysql /var/lib/mysql
5.修改配置文件
vim /etc/my.cnf
[client]
socket = /var/lib/mysql/mysqld.sock
[mysqld]
#skip_grant_tables
port=3300
character-set-server=utf8
datadir=/usr/local/mysql5.7/data/mysql
basedir=/usr/local/mysql5.7
user=mysql
symbolic-links=0
#socket = /var/lib/mysql/mysqld.sock
# sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
group_concat_max_len=204800
lower_case_table_names=1
max_allowed_packet=50M
[mysqld_safe]
character-set-server=utf8
6.初始化仓库
/usr/local/mysql5.7/bin/mysqld --initialize --user=mysql
ln /var/lib/mysql/mysqld.sock /tmp/mysql.sock
7.保存初始密码
8.启动mysql
/usr/local/mysql5.7/bin/mysqld_safe --user=mysql
9.修改root密码
/usr/local/mysql5.7/bin/mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'supplier';
flush privileges;
10.添加远程访问权限
create user 'root'@'%' IDENTIFIED BY 'supplier';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' ;
flush privileges;
11.如果忘记密码
配置文件添加 配置项,连接数据库修改密码
[mysqld]
skip_grant_tables
/usr/local/mysql5.7/bin/mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'supplier';
ALTER USER 'root'@'%' IDENTIFIED BY 'supplier';
12.数据备份
/usr/local/mysql5.7/bin/mysqldump -uroot -p database > /root/database.sql
12.数据导入
1:
/usr/local/mysql5.7/bin/mysql -uroot -p < /root/database.sql
2:
mysql> create database abc; # 创建数据库
mysql> use abc; # 使用已创建的数据库
mysql> set names utf8; # 设置编码
mysql> source /root/database.sql # 导入备份数据库