文章目录
- 资源下载
- 将mysql解压到`/usr/local/mysql`
- 更改`/etc/my.cnf`
- 创建数据存放路径
- 用户组配置
- 配置mysql用户的执行权限
- 数据初始化
- 启动服务
- 环境变量配置
- 修改初始密码
- 防火墙管理,开启3306端口远程访问
资源下载
链接:https://pan.baidu.com/s/1ozfedVlRDsB8dqfJtol4mw 密码:tzi1
将mysql解压到/usr/local/mysql
tar -xvf mysql-8.0.20-linux-glibc2.12-i686.tar.xzmv mysql-8.0.20-linux-glibc2.12-i686 /usr/local/mysql
更改/etc/my.cnf
原文件有数据直接覆盖即可
[mysqld]bind-address=0.0.0.0port=3306user=mysqlbasedir=/usr/local/mysql datadir=/data/mysqlsocket=/tmp/mysql.socklog-error=/data/mysql/mysql.errpid-file=/data/mysql/mysql.pid#character configcharacter_set_server=utf8mb4symbolic-links=0explicit_defaults_for_timestamp=true!includedir /etc/my.cnf.d
这里面有几个路径非常重要:
basedir:mysql的存放位置
datadir:数据存放位置
log-error:临时密码查看
创建数据存放路径
mkdir -r /data/mysql
用户组配置
groupadd mysql
useradd mysql -g mysql
配置mysql用户的执行权限
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
数据初始化
cd /usr/local/mysql/bin
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
启动的过程中容易发生一个错误:
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方法:
# 缺什么安什么
yum install libaio.so.1
启动服务
cd /usr/local/mysql/support-files
./mysql.server start
环境变量配置
[root@localhost bin]# vim /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
修改初始密码
前面说过,初始密码在log-error
里面,我们的配置是:
log-error=/data/mysql/mysql.err
现在查看一下:
cat /data/mysql/mysql.err
使用该密码登录mysql:
cd /usr/local/mysql/bin/./mysql -uroot -pgVecql/Sh3<I
更改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password;
FLUSH PRIVILEGES;
授予远程访问权限:
use mysql;
update user set host = "%" where user = "root";
FLUSH PRIVILEGES;
防火墙管理,开启3306端口远程访问
开启3306端口:
vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙:
service iptables restart