1、安装依赖
yum install -y cmake make gcc gcc-c++ libaio ncurses ncurses-devel
cd /usr/local/src
链接:https://pan.baidu.com/s/18tSRnB7FBb7Ak9Sr665Jeg 密码:86nj 这是5.7.22版本,下载上传到服务器
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz(不能下载了)
如果上面链接不能下载,去官网找,下面的步骤都一样
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz(用这个,后续的步骤都一样)
解压
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
将解压的复制到 /usr/local/mysql 目录
cp -r mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
2、添加系统mysql组和mysql用户
添加系统mysql组
groupadd mysql
添加mysql用户
useradd -r -g mysql mysql (添加完成后可用id mysql查看)
3、安装数据库
切到mysql目录
cd /usr/local/mysql
修改当前目录拥有者为mysql用户
chown -R mysql:mysql ./
安装数据库
bin/mysqld —initialize —user=mysql —basedir=/usr/local/mysql —datadir=/usr/local/mysql/data
生成了临时密码
4、配置my.cnf
vim /etc/my.cnf (直接把下面内容复制上就行)
[mysqld]
character_set_server=utf8
init_connect=’SET NAMES utf8’
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
max_connections=1000
pid-file=/usr/local/mysql/data/mysqld.pid
添加开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改mysqld文件内容
vim /etc/init.d/mysqld
添加路径 在46行
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
5、启动mysql
service mysqld start
6、 加入开机起动
chkconfig —add mysqld
7、添加软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin
8、mysql客户端登录
mysql -uroot -p 上面初始化时的密码
9、修改密码
授权root用户
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘kyd8899’ WITH GRANT OPTION;
刷新权限
flush privileges;