解压并移动到指定目录
- 解压
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
- 重命名
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
- 移动目录
mv mysql/ /usr/local/
- 安装MySQL依赖库
apt-get install libaio1
配置和使用MySQL
- 创建MySQL组
groupadd mysql
- 创建MySQL用户
useradd -g mysql mysql
- 创建mysql-files目录
cd /usr/local/mysql
mkdir mysql-files
- 修改mysql-files文件夹权限
cd /usr/local/mysql
chmod 750 mysql-files
- 修改文件的额所有者
cd /usr/local/mysql
chown -R root .
- 改变用户组
cd /usr/local/mysql
chgrp -R mysql .
- 安装初始化
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql
- 执行后在最后一行会有一个初始化密码,用于root账号的首次登陆
root@localhost:*******
- 生成证书
cd /usr/local/mysql
bin/mysql_ssl_rsa_setup
- 把权限修改回来
cd /usr/local/mysql
chown -R root .
chown -R mysql data mysql-files
- 启动MySQL数据库
cd /usr/local/mysql
bin/mysqld_safe --user=mysql & [&表示以后台的方式启动]
- 登录测试并需改root密码
cd /usr/local/mysql/bin
./mysql -u root -p
提示输入密码,在输入上面自动生成的密码
修改root密码
mysql> set password = '123456';
设置root账户远程登陆
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
配置服务自动启动
- 复制服务文件到/etc/init.d
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
- 安装sysv-rc-conf
apt-get install sysv-rc-conf
- 启动sysv-rc-conf
sysv-rc-conf

按空格键出现X,然后按Q退出。重启即可。
服务的相关操作命令:
服务状态
service mysql.server status
服务启动
service mysql.server start
服务停止
service mysql.server stop
- 配置环境变量
vi /etc/profile
添加如下加粗内容
if [ "$PS1" ]; then
if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
export PATH=$PATH:/usr/local/mysql/bin
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi