mysql的rpm包下载地址
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
下载,mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 大小520.5M
卸载CentOS7.4系统自带的mariadb
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -qa|grep mysql
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -qa|grep mariadb
[root@localhost ~]#
将mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 拷贝到/tmp下,并解压
[root@localhost tmp]# tar xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-test-5.7.29-1.el7.x86_64.rpm
mysql-community-embedded-5.7.29-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-5.7.29-1.el7.x86_64.rpm
mysql-community-client-5.7.29-1.el7.x86_64.rpm
mysql-community-server-5.7.29-1.el7.x86_64.rpm
mysql-community-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm
mysql-community-common-5.7.29-1.el7.x86_64.rpm
依次安装:
mysql-community-common-5.7.29-1.el7.x86_64.rpm、
mysql-community-libs-5.7.29-1.el7.x86_64.rpm、
mysql-community-client-5.7.29-1.el7.x86_64.rpm、
mysql-community-server-5.7.29-1.el7.x86_64.rpm
[root@localhost tmp]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
[root@localhost tmp]# rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
[root@localhost tmp]# rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
[root@localhost tmp]# rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm
重启系统,来启动mysql服务
[root@localhost tmp]# reboot
查看防火墙端口,开放3306端口
查看防火墙的状态的命令为:sudo systemctl status firewalld。
打开防火墙的方式有两种,一种是打开后重启会恢复回原来的状态,命令为:sudo systemctl start firewalld;
另一种是打开后重启不会恢复到原来的状态,命令为:sudo systemctl enable firewalld,这种方式输入命令后要重启系统才会生效。
关闭防火墙的方式也有两种,和打开相对应,命令分别为
sudo systemctl stop firewalld
sudo systemctl disable firewalld。
[root@localhost ~]# firewall-cmd --query-port=3306/tcp
no
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --query-port=3306/tcp
yes
[root@localhost ~]#
获取mysql的root用户的初始密码
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2020-01-14T01:09:01.515663Z 1 [Note] A temporary password is generated for root@localhost: vx*biwua,8/Q
[root@localhost ~]#
以获取mysql的root用户的初始密码登录数据库
[root@localhost ~]# mysql -u root -p
Enter password:
修改root密码
mysql> alter user 'root'@'localhost' identified by '2020root$PWD';
Query OK, 0 rows affected (0.01 sec)
mysql> set global validate_password_length=4;
mysql> set global validate_password_policy=0;
mysql> set password = password("000000");
mysql> update mysql.user set host='%' where user='root';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
允许以root身份远程登录mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '2020root$PWD' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
修改mysql的字符集为utf8
编辑文件/etc/my.conf,设置字符集为utf8
vim /etc/my.cnf
# 增加以下几个设置
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
重起mysql服务
[root@localhost ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@localhost ~]#