1.获取rpm包
安装前,首先要关闭防火墙和selinux
mysql官方网站为www.mysql.com
wget https://dev.mysql.com/get/mysql80-community-releaseel7-3.noarch.rpm
wget 官网得到的地址 或者下载到本地然后上传到服务器
2.安装mysql的yum仓库
[root@mysql ~]# rpm -ivh 进行解压
[root@mysql ~]# yum -y install yum-utils 安装yum工具包
3.配置yum源
[root@mysql ~]# vim /etc/yum.repos.d/mysql-community.repo
#Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
#Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
#Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-connectors-community]
name=MySQL Connectors Community
"/etc/yum.repos.d/mysql-community.repo" 72L, 2076C
根据mysql版本开启,我的是5.7所以开了5.7,1表示开启。0表示关闭
4.安装数据库
[root@mysql ~]# yum install -y mysql-community-server
[root@mysql ~]# systemctl start mysqld 启动服务
[root@mysql ~]# systemctl enable mysqld 设置开机启动
5.查找密码
密码保存在日志文件中
[root@mysql ~]# grep password /var/log/mysqld.log
2019-08-18T14:03:51.991454Z 1 [Note] A temporary password is generated for root@localhost: woHtkMgau9,w
冒号后的都是密码
6.修改密码(两种方式)
第一种
[root@mysql ~]# mysql -uroot -p'woHtkMgau9,w'
mysql> alter user 'root'@'localhost' identified by 'ChenChao@123';
第二种
[root@mysql ~]# mysqladmin -uroot -p'ChenChao@123' password 'ChenChao!123'
mysqladmin: [Warning] Using a password on the command line interface can be
insecure.
Warning: Since password will be sent to server in plain text, use ssl connection
to ensure password safety.
——————————————————————————————————
启动 mysqld 服务
[root@mysql ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
查看服务状态
[root@mysql ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
停止 mysqld 服务
[root@mysql ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
查看服务的监听端口
[root@mysql ~]# ss -ntal
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 80 :::3306 :::*
网友评论