1. 下载MySQL二进制包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.xx-linux-glibc2.12-x86_64.tar.gz
2. 解压缩到/usr/local/mysql
tar -zxvf mysql-5.7.xx-linux-glibc2.12-x86_64.tar.gz -C /usr/local
mv /usr/local/mysql-5.7.xx-linux-glibc2.12-x86_64 /usr/local/mysql
3. 创建my.cnf配置文件
tee /etc/my.cnf <<-'EOF'
[mysqld]
datadir=/usr/local/mysql/data
port=3306
EOF
4. 初始化数据库
useradd mysql
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
5. 启动MySQL服务
/usr/local/mysql/support-files/mysql.server start
6. 设置root用户密码
grep 'temporary password' /usr/local/mysql/data/localhost.localdomain.err
hostname的值
localhost.localdomain
grep 'temporary password' /usr/local/mysql/data/xxx.err
7、使用临时密码登录MySQL,并更改root密码
/usr/local/mysql/bin/mysql -u root -pNewPassword
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
ALTER USER 'root'@'%' IDENTIFIED BY 'NewPassword';
8、配置PATH
vi /etc/profile
export PATH="$PATH:/usr/local/mysql/bin:/usr/local/mysql/support-files"
9、常用运维方式
1、启动关闭
mysql.server start/stop
2、没有了