MySQL-yum方式安装

###1. 获取rpm包
wget 官网得到的地址 或者下载到本地然后上传到服务器

###2. 安装mysql的yum仓库

[root@mysql-server ~]# rpm -ivh (mysql的rpm包名字)
[root@mysql-server ~]# yum -y install yum-utils          安装yum工具包

###3. 配置yum源
根据版本打开 我的是5.7

[root@mysql-server ~]# 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-server ~]# yum install -y mysql-community-server
[root@mysql-server ~]# systemctl start mysqld                                   启动服务
[root@mysql-server ~]# systemctl enable mysqld                                 设置开机启动

###5. 查找密码

密码保存在日志文件中
[root@mysql-server ~]# 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-server ~]# mysql -uroot -p'woHtkMgau9,w' 
mysql> alter user 'root'@'localhost' identified by 'ChenChao@123';

第二种
[root@mysql-server ~]# 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-server ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service

#####查看服务状态

[root@mysql-server ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service

#####停止 mysqld 服务

[root@mysql-server ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service

#####查看服务的监听端口
默认端口是3306

[root@mysql-server ~]# 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               :::*
发布了92 篇原创文章 · 获赞 0 · 访问量 1442

猜你喜欢

转载自blog.csdn.net/Forgetfanhua/article/details/105249184