一,准备工作。
查看系统版本:
[[email protected] ~]# uname -a Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [[email protected] ~]#
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
[[email protected] ~]# rpm -qa|grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 [[email protected] ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 [[email protected] ~]# rpm -qa|grep mariadb [[email protected] ~]#
将mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 拷贝到/tmp下,并解压
解压
[[email protected] 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
安装common
[[email protected] tmp]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm warning: mysql-community-common-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-5.7.29-1.e################################# [100%] [[email protected] tmp]#
安装libs
[[email protected] tmp]# rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm warning: mysql-community-libs-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-5.7.29-1.el7################################# [100%] [[email protected] tmp]#
安装client
[[email protected] tmp]# rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm warning: mysql-community-client-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-5.7.29-1.e################################# [100%] [[email protected] tmp]#
安装server
[[email protected] tmp]# rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm warning: mysql-community-server-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-5.7.29-1.e################################# [100%] [[email protected] tmp]#
这一步如如果报错,缺依赖的问题,需要挂载CentOS7.4的系统iso镜像,安装perl依赖、net-tools依赖
重启系统,来启动mysql服务
[[email protected] tmp]# reboot
查看防火墙端口,开放3306端口
[[email protected] ~]# firewall-cmd --query-port=3306/tcp
no
[[email protected] ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[[email protected] ~]# firewall-cmd --reload
success
[[email protected] ~]# firewall-cmd --query-port=3306/tcp
yes
[[email protected] ~]#
设置数据库日志过期天数为14天
获取mysql的root用户的初始密码
[[email protected] ~]# grep ‘password‘ /var/log/mysqld.log 2020-01-14T01:09:01.515663Z 1 [Note] A temporary password is generated for [email protected]: vx*biwua,8/Q [[email protected] ~]#
以获取mysql的root用户的初始密码登录数据库
[[email protected] ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.29
修改root密码
mysql> alter user ‘root‘@‘localhost‘ identified by ‘2020root$PWD‘; Query OK, 0 rows affected (0.01 sec) mysql>
使密码即时生效
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
vi /etc/my.cnf
重起mysql服务
[[email protected] ~]# service mysqld restart Redirecting to /bin/systemctl restart mysqld.service [[email protected] ~]#
测试登陆
原文地址:https://www.cnblogs.com/yisheng163/p/12190216.html