-
下载mysql安装包
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
-
查看是否已经安装了mysql
rpm -qa | grep mysql
-
解压安装包到/usr/local目录下
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql
-
创建用户组和用户并修改权限
groupadd mysql
useradd -r -g mysql mysql
chown mysql:mysql -R /usr/local/mysql
-
创建mysql数据目录
cd /
mkdir -p data
cd data/
mkdir -p mysql/
chown mysql:mysql -R /data/mysql
-
卸载Centos7自带的Maridb数据库
rpm -qa | grep mariadb
rpm -e --nodeps mariadb*
yum -y remove mari*
-
修改配置
vi /etc/my.cnf
[mysql]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sockt
[mysqld]
socket=/usr/local/mysql/mysql.sockt
log_error=/data/mysql/error.log
pid_file=/data/mysql/mysql.pid
basedir=/usr/local/mysql
datadir=/data/mysql
port = 3306
lower_case_table_names=1
character-set-server=utf8
max_connections=2000
default-storage-engine=INNODB
explicit_defaults_for_timestamp=true
skip-grant-tables
-
初始化mysql
chown 777 /etc/my.cnf
rpm -qa | grep libaio
yum install libaio
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
-
配置自启动和相关服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 777 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
-
启动mysql并更改密码
service mysqld start
service mysqld stop
service mysqld restart
mysql -u root -p
UPDATE mysql.user SET authentication_string=PASSWORD('新密码') where USER='root';
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
flush privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
flush privileges;