1、下载mysql文件
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
2、MySQL安装
1.将压缩文件移动到:/usr/local 目录下并解压
tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
2.数据库目录名称太长,修改名称
mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
3.创建数据目录并赋权 :
cd /data
mkdir /data/mysqldata/data
chmod -R 777 /data/mysqldata/data
4.创建用户 、组、并将用户加入组,修改配置文件
groupadd mysql
useradd -g mysql mysql
修改MySQL 配置文件: vi /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysqldata/data
tmpdir =/data/mysqldata/tmp
#character config
character_set_server=utf8mb4
explicit_defaults_for_timestamp=true
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
# 配置mysql的安装目录
basedir=/usr/local/mysql# 配置mysql数据库的数据的存放目录
datadir=/data/mysqldata/data
5.MySQL 安装并初始化mysql
进入mysql bin 目录下面
cd /usr/local/mysql/bin/
执行命令(注意目录不能错)
./mysqld --initialize --user=mysql --datadir=/data/mysqldata/data/ --basedir=/usr/local/mysql/
有很多人在执行的过程中报错:
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
是因为没有安装依赖 libaio
yum -y install libaio-devel.x86_64
yum -y install numactl
记住初始密码
6.添加软连接,并重启mysql服务
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# 开机自启
chkconfig mysql on
#启动mysql
service mysql start
7.登录mysql 修改密码,访问权限
mysql -p
输入密码
修改密码(设置密码尽量设置复杂一点,拒绝弱口令)
set password=password('root');
flush privileges;
或
set password for 'root'@'localhost' = password('pEG%pcb@cGNgc96v');
flush privileges;
修改访问权限 (将localhost 改为% ,全都能访问)
use mysql;
update user set Host='%' where User='root';
flush privileges;