@[toc]
环境
[root@iZayh3eg8rjhsjZ ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core
详细操作步骤
1 确保服务器系统处于最新状态
[root@iZayh3eg8rjhsjZ ~]# yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
···(此处省略很多很多)
Updated:
perl.x86_64 4:5.16.3-294.el7_6 perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-libs.x86_64 4:5.16.3-294.el7_6 perl-macros.x86_64 4:5.16.3-294.el7_6
systemd.x86_64 0:219-62.el7_6.2 systemd-libs.x86_64 0:219-62.el7_6.2 systemd-networkd.x86_64 0:219-62.el7_6.2 systemd-sysv.x86_64 0:219-62.el7_6.2
tzdata.noarch 0:2018i-1.el7
Complete!
主要是看到最后面有 Complete
说明安装成功
2 重启服务器
[root@iZayh3eg8rjhsjZ ~]# reboot
Connection timed out
3 确认是否已经安装 mysql
[root@iZayh3eg8rjhsjZ ~]# yum list installed | grep mysql
# 如果已经安装,可以卸载
4 下载MySql安装包
[root@iZayh3eg8rjhsjZ ~]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
warning: /var/tmp/rpm-tmp.NpAFqn: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-8 ################################# [100%]
[root@iZayh3eg8rjhsjZ ~]# yum list installed | grep mysql
mysql57-community-release.noarch el7-8 installed
5 安装 MySql
[root@iZayh3eg8rjhsjZ ~]# yum install -y mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
mysql-connectors-community | 2.5 kB 00:00:00
···(此处省略很多很多)
Installed:
mysql-community-client.x86_64 0:5.7.25-1.el7 mysql-community-devel.x86_64 0:5.7.25-1.el7 mysql-community-libs.x86_64 0:5.7.25-1.el7 mysql-community-libs-compat.x86_64 0:5.7.25-1.el7
mysql-community-server.x86_64 0:5.7.25-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-common.x86_64 0:5.7.25-1.el7
Replaced:
mariadb.x86_64 1:5.5.60-1.el7_5 mariadb-devel.x86_64 1:5.5.60-1.el7_5 mariadb-libs.x86_64 1:5.5.60-1.el7_5
Complete!
主要是看到最后面有 Complete
说明安装成功
6 设置开机启动Mysql
[root@iZayh3eg8rjhsjZ ~]# systemctl enable mysqld.service
检查是否已经安装了开机自动启动
[root@iZayh3eg8rjhsjZ ~]# systemctl list-unit-files | grep mysqld
mysqld.service enabled
mysqld@.service disabled
7 启动Mysql服务
[root@iZayh3eg8rjhsjZ ~]# systemctl start mysqld.service
8 设置root密码
查询Mysql默认密码
[root@iZayh3eg8rjhsjZ ~]# grep 'temporary password' /var/log/mysqld.log
2019-01-31T06:55:04.807770Z 1 [Note] A temporary password is generated for root@localhost: **********)h
登陆后
[root@iZayh3eg8rjhsjZ ~]# 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.25
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
设置密码
mysql> set PASSWORD = PASSWORD('Abc123!_');
Query OK, 0 rows affected, 1 warning (0.00 sec)
9 开启远程登录,授权root远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Abc123!_' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
命令立即执行生效
mysql>flush privileges;