安装过程
- 一.官网下载离线tar包
- 二.安装MySQL
- 三.验证
一.官网下载离线tar包
点击此处下载
链接:https://pan.baidu.com/s/1_p2esJax95Ow39wfgM_paw
提取码:g415
–来自百度网盘超级会员V2的分享
二.安装MySQL
1.上传到/usr/local目录下
2.解压安装包
#两次解压
tar xf mysql-8.0.32-el7-x86_64.tar
tar xf mysql-8.0.32-el7-x86_64.tar.gz
3.修改文件名称
mv mysql-8.0.32-el7-x86_64 mysql
4.创建用户和组
#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -r -g mysql mysql
5.在/usr/local/mysql 目录下创建一个 data 文件夹
cd /usr/local/mysql
mkdir data
6.将安装目录 /usr/local/mysql/ 的所有者及所属组改为 mysql
chown -R mysql:mysql /usr/local/mysql/
7.修改配置文件 my.cnf (如果没有,新增一个)
[mysqld]
server_id=1
log-bin=mysql-bin
binlog-format=ROW
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
skip_ssl
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1#忽略大小写
lower_case_table_names=1
character_set_server=utf8pid-file = /usr/local/mysql/data/mysql.pid
8.初始化
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
如果出现以下错误:
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
执行: yum install -y libaio
记住密码
9.把mysqld添加至systemctl进行管理
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld.server
#添加执行权限
chmod +x /etc/rc.d/init.d/mysqld.server
10.配置环境变量
vim /etc/profile在底部添加:
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
:wq
保存退出后执行:source /etc/profile
11. systemctl 配置重载
systemctl daemon-reload
12.启动MySQL
systemctl start mysql
mysql -uroot -p上面的密码
13.修改密码
mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
mysql> flush privileges;
14.允许使用某个用户名及密码从任何主机连接到该 mysql 服务
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
15.退出重启服务
mysql> exit
service mysql restart