官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
注意:在新版本的CentOS7中,默认的数据库已更新为了Mariadb,Mariadb是mysql的一个分支,同时存在可能会出现冲突,因此先检查并删除linux上内嵌的Mariadb
[root@192 ~]# rpm -qa|grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@192 ~]# rpm -qa|grep mariadb|xargs rpm -e --nodeps
[root@192 ~]# rpm -qa|grep -i mariadb
我这里将 mysql tar 包放在了/opt/soft 目录下
[root@192 opt]# cd /opt/soft
[root@192 soft]# ls
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
[root@192 soft]# groupadd mysql
[root@192 soft]# useradd -r -g mysql mysql
#创建mysql数据目录
[root@192 soft]# mkdir -p /data/mysql
#赋予权限;将/data/mysql下的所有文件与子目录的拥有者皆设为 mysql ,群体的使用者 mysql
[root@192 soft]# chown mysql:mysql -R /data/mysql
vim /etc/my.cnf
将下面内容粘贴进去
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=basedir=/usr/local/mysql/mysql-5.7.34-linux-glibc2.12-x86_64
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
进入到bin目录 !!!,这里注意自己的目录对不对
[root@192 bin]# pwd
/usr/local/mysql/mysql-5.7.34-linux-glibc2.12-x86_64/bin./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/mysql-5.7.34-linux-glibc2.12-x86_64 --datadir=/data/mysql/ --user=mysql --initialize
[root@192 bin]# cp /usr/local/mysql/mysql-5.7.34-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysql
cat /data/mysql/mysql.err
[root@192 bin]# service mysql start
Unit mysql.service could not be found.
Starting MySQL. SUCCESS!
./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34Copyright © 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
mysql> SET PASSWORD = PASSWORD(‘qb031219’);
Query OK, 0 rows affected, 1 warning (0.02 sec)mysql> ALTER USER ‘root’@‘localhost’ PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)#设置远程主机登录
mysql> GRANT ALL PRIVILEGES ON . TO ‘your username’@’%’ IDENTIFIED BY ‘qb031219’;
Query OK, 0 rows affected, 1 warning (0.00 sec)#执行以下命令,为root 用户添加远程登录的能力。
mysql> GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY “qb031219”;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@192 bin]# firewall-cmd --query-port=3306/tcp
no
[root@192 bin]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@192 bin]# firewall-cmd --state
running
[root@192 bin]# firewall-cmd --reload
success
解释下my.cnf 配置中的信息
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=basedir=/usr/local/mysql/mysql-5.7.34-linux-glibc2.12-x86_64
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0