#安装依赖
yum update
yum install -y gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel libaio
#下载,解压,重命名
mkdir -p /data/app/ mkdir -p /data/download/ cd /data/download/ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /data/app/ mv /data/app/mysql-5.7.19-linux-glibc2.12-x86_64/ /data/app/mysql
#新建用户组和用户
cd /data/app/mysql/
groupadd mysql
useradd mysql -g mysql
#创建目录并授权
mkdir data mysql-files chmod 750 mysql-files chown -R mysql . chgrp -R mysql . mkdir -p /var/log/mariadb/ touch /var/log/mariadb/mariadb.log chown -R mysql:mysql /var/log/mariadb chown -R root . chown -R mysql data mysql-files chown -R mysql:mysql /data/app/mysql/data chmod -R 755 /data/app/mysql/data
#初始化MySQL
bin/mysqld --initialize --user=mysql
#mysql 临时密码
#[注意]root@localhost生成临时密码:kkp_8wQ.59ij,也就是root@localhost:后的字符串
#添加到MySQL 启动脚本到系统服务
cp /data/app/mysql/support-files/mysql.server /etc/init.d/mysqld
#编辑或者修改
vim /etc/init.d/mysqld basedir=/data/app/mysql datadir=/data/app/mysql/data
#启动mysql
/etc/init.d/mysqld start
#加入开机启动
chkconfig --add mysqld
chkconfig mysqld on
#映射一个链接到/usr/bin目录下,建立一个链接文件
ln -s /data/app/mysql/bin/mysql /usr/bin
#登陆mysql
mysql -u root -p 错误提示:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) #解决办法 find / -name mysql.sock ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
#设置root密码
mysql -u root -p mysql> ALTER USER 'root'@'localhost' identified by 'mima';
mysql> flush privileges;
mysql> exit;
#开启远程登录
#关闭防火墙
systemctl stop firewalld.service
mysql -u root -h 127.0.0.1 -p mysql> use mysql; mysql> update user set host = '%' where user ='root'; mysql> flush privileges; #或者 mysql> grant all privileges on *.* to 'root'@'%' identified by 'bin312967328' with grant option; mysql> flush privileges;
#查看mysql.user表中存在哪些帐户 以及它们的密码是否为空:
SELECT User, Host, HEX(authentication_string) FROM mysql.user;