1. 官网下载压缩包
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.40-el7-x86_64.tar.gz
2. 卸载系统自带的Mariadb
rpm -qa|grep mariadb
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
3.创建mysql用户与用户组
groupadd mysql
useradd -g mysql mysql
passwd mysql
4.解压安装
tar -xvf mysql-5.7.40-el7-x86_64.tar.gz
mv mysql-5.7.40-el7-x86_64 mysql57/
cd mysql57/
mkdir data
chown -R mysql:mysql data
5. 在etc下新建配置文件my.cnf
[mysql]
default-character-set=utf8
[mysqld]
skip-name-resolve
port = 3306
basedir=/usr/local/mysql57
datadir=/usr/local/mysql57/data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
skip-grant-tables
[mysqld_safe]
error-log=/usr/local/error.log
pid-file=/usr/local/mysql.pid
6. 初始化安装
bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql57/ --datadir=/usr/local/mysql57/data/
cp ./support-files/mysql.server /etc/init.d/mysqld
chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysqld
7. 重启
/etc/init.d/mysqld restart
8.开机启动
chkconfig --level 35 mysqld on
chkconfig --list mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
service mysqld status
9.修改初始密码
cat /root/.mysql_secret
mysql -uroot -p
set PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.01 sec)
10. 添加远程访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;