1.检查系统是否有mysql,如果有统统删除
find / -name mysql
2.创建临时目录,下载并上传mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz到该目录
mkdir /usr/local/tmp
3.解压,把解压后的文件夹移动到/usr/local/mysql
tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.27-linux-glibc2.12-x86_64 ../mysql
4.添加用户
groupadd mysql
useradd -r -g mysql mysql
id mysql
5.创建data目录
cd /usr/local/mysql
mkdir data
6.更改mysql目录权限
chown -R mysql:mysql /usr/local/mysql
7.配置my.cnf文件
rm -f /etc/my.cnf
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
init-connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
8.初始化mysql
cd /usr/local/mysql/bin
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
9.启动mysql
cd /usr/local/mysql/bin
./mysqld_safe --user=mysql &
10.修改密码,设置外网可以访问
./mysql -u root -p
use mysql;
update user set authentication_string=password('root') where user='root';
update user set host='%' where user ='root';
flush privileges;
select host,user from user;
exit;
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
11.设置开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --list
chkconfig mysql on
service mysql status
service mysql start
service mysql stop
12.添加mysql环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
mysql -u root -p