1.下载
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
2.解压
tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
3.创建数据目录
mkdir -p /data/mysql
4.新建mysql用户、组及目录
# ---新建一个msyql组
# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql ---新建msyql用户禁止登录shell
改变目录属有者
#cd /usr/local/mysql
#pwd
#chown -R mysql .
#chgrp -R mysql .
chown -R mysql /data/mysql
5.配置参数
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
初始化后会返回一个临时密码
bin/mysql_ssl_rsa_setup --datadir=/data/mysql
6.修改配置
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/my.cnf
[mysqld] server-id = 1 port = 3306 basedir =/usr/local/mysql datadir = /data/mysql transaction_isolation = READ-COMMITTED character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect=‘SET NAMES utf8mb4‘ lower_case_table_names = 1 max_connections = 400
7.启动mysql
/etc/init.d/mysql start
登录
mysql -hlocalhost -uroot -p
--如果出现:-bash: mysql: command not found
--就执行: # ln -s /usr/local/mysql/bin/mysql /usr/bin --没有出现就不用执行
输入上面的临时密码
修改密码
set password=password('root');
设置root账户的host地址(修改了才可以远程连接)
mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql>flush privileges;
8.添加系统路径
vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
9.配置mysql自动启动
# chmod 755 /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig --level 345 mysql on